From 2014c4b3dae549d466b11a5bbcd514eecfc99528 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 23 Mar 2024 13:13:23 -0700 Subject: [PATCH] Fix: for duplicate candidates The same candidate was found to be in the download two times with the same filer_id. This caused the database insert to fail. The candidates added to the database will now have unique filer_id fields. --- .../src/efile.api/candidates.update.service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/update-command/src/efile.api/candidates.update.service.ts b/apps/update-command/src/efile.api/candidates.update.service.ts index 2794063..9aff20f 100644 --- a/apps/update-command/src/efile.api/candidates.update.service.ts +++ b/apps/update-command/src/efile.api/candidates.update.service.ts @@ -62,8 +62,15 @@ export class CandidatesUpdateService { (candidate) => candidate.jurisdiction_code.toUpperCase() === 'CIT', ); - if (filteredClasses.length > 0) { - await this.candidateAddService.addCandidate(filteredClasses); + // Remove classes with duplicate "filer_id" fields + const uniqueClasses = [ + ...new Map( + filteredClasses.map((item) => [item['filer_id'], item]), + ).values(), + ]; + + if (uniqueClasses.length > 0) { + await this.candidateAddService.addCandidate(uniqueClasses); } const generalClasses = await this.getCandidatesClasses(