diff --git a/app/models/bulk_search.rb b/app/models/bulk_search.rb index c6a7bac6..4080d886 100644 --- a/app/models/bulk_search.rb +++ b/app/models/bulk_search.rb @@ -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 @@ -74,7 +74,7 @@ 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 @@ -90,4 +90,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 \ No newline at end of file