Skip to content

Commit

Permalink
Merge pull request #896 from DFE-Digital/390-ctr-bulk-search-issue-wh…
Browse files Browse the repository at this point in the history
…en-a-trn-starts-with-0

Fix issue where trn starts with zero
  • Loading branch information
richardpattinson authored Oct 28, 2024
2 parents 7ebc882 + 854bc03 commit b66bc23
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 b66bc23

Please sign in to comment.