Skip to content

Commit

Permalink
Fix issue where trn starts with zero
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpattinson committed Oct 24, 2024
1 parent 21776c9 commit 854bc03
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/models/bulk_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def call

def not_found
@not_found ||= csv.map { |row|
next if results.any? { |teacher| teacher.trn == row["TRN"] }
next if results.any? { |teacher| teacher.trn == sanitise_trn(row["TRN"]) }

Hashie::Mash.new(trn: row["TRN"], date_of_birth: Date.parse(row["Date of birth"]))
Hashie::Mash.new(trn: sanitise_trn(row["TRN"]), date_of_birth: Date.parse(row["Date of birth"]))
}.compact
end

Expand Down Expand Up @@ -74,7 +74,8 @@ def find_all(queries)

def response
@response ||= begin
queries = csv.map { |row| { trn: row["TRN"], dateOfBirth: Date.parse(row["Date of birth"]) } }.compact
queries = csv.map { |row|
{ trn: sanitise_trn(row["TRN"]), dateOfBirth: Date.parse(row["Date of birth"]) } }.compact
find_all(queries)
end
end
Expand All @@ -90,4 +91,9 @@ def search_client
token: ENV["QUALIFICATIONS_API_FIXED_TOKEN"]
)
end

def sanitise_trn(trn)
# Ensure the TRN is exactly 7 characters by padding with leading zeros, csv formatting can remove leading zeros
trn.to_s.rjust(7, '0')
end
end

0 comments on commit 854bc03

Please sign in to comment.