From 66da653c593719fc6d82faba39f615a8939a13e1 Mon Sep 17 00:00:00 2001 From: David Bayly Date: Thu, 21 Nov 2024 12:58:49 -0700 Subject: [PATCH 1/2] Sync now ignores BCCNM milestones --- apps/api/src/applicant/external-api.service.ts | 16 +++++++++++----- packages/common/src/enum/milestone-status.ts | 5 +++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/api/src/applicant/external-api.service.ts b/apps/api/src/applicant/external-api.service.ts index 336e8bb2..27d6dd9b 100644 --- a/apps/api/src/applicant/external-api.service.ts +++ b/apps/api/src/applicant/external-api.service.ts @@ -21,7 +21,7 @@ import { } from 'typeorm'; import dayjs from 'dayjs'; import _ from 'lodash'; -import { AtsApplicant, Authorities, STATUS, StatusCategory } from '@ien/common'; +import { AtsApplicant, Authorities, BCCNM_NEW_FIELDS, STATUS, StatusCategory } from '@ien/common'; import { ExternalRequest } from 'src/common/external-request'; import { AppLogger } from 'src/common/logger.service'; import { IENApplicant } from './entity/ienapplicant.entity'; @@ -378,16 +378,22 @@ export class ExternalAPIService { manager: EntityManager, ): Promise { let removedCount = 0; + const statuses = await this.ienapplicantStatusRepository.find(); + const bccnm_new_statuses = statuses.filter(value => + BCCNM_NEW_FIELDS.some(bccnm_new_field => value.status === bccnm_new_field.toString()), + ); await Promise.all( applicants.map(async a => { - const audits: { id: string; status_id: string }[] = await manager.query(` + const query = ` SELECT "audit"."id" id, "status"."id" status_id FROM "ien_applicant_status_audit" "audit" INNER JOIN "ien_applicant_status" "status" ON "status"."id" = "audit"."status_id" WHERE "audit"."applicant_id" = '${a.applicant_id.toLowerCase()}' AND - "status"."category" != 'IEN Recruitment Process'; - `); + "status"."category" != 'IEN Recruitment Process' AND + "status"."id" NOT IN ('${bccnm_new_statuses.map(status => status.id).join("','")}') + `; + const audits: { id: string; status_id: string }[] = await manager.query(query); if (!audits?.length) return; @@ -468,7 +474,7 @@ export class ExternalAPIService { ['id'], ); this.logger.log( - `Signed Return of Service Agreement milestones updated: ${result.raw.length}`, + `Signed Return of Service Agreement milestones updated: ${result?.raw?.length}`, 'ATS-SYNC', ); } diff --git a/packages/common/src/enum/milestone-status.ts b/packages/common/src/enum/milestone-status.ts index 659d6ccc..a50e5a46 100644 --- a/packages/common/src/enum/milestone-status.ts +++ b/packages/common/src/enum/milestone-status.ts @@ -74,6 +74,11 @@ export enum STATUS { END_OF_JOURNEY_COMPLETE = 'End of Journey - Journey Complete', END_OF_JOURNEY_INCOMPLETE = 'End of Journey - Journey Incomplete', } +export const BCCNM_NEW_FIELDS = [ + STATUS.BCCNM_APPLICATION_COMPLETE_DATE, + STATUS.BCCNM_DECISION_DATE, + STATUS.BCCNM_REGISTRATION_DATE, +]; export const COMPLETED_STATUSES = [ STATUS.PRE_SCREEN_NOT_PASSED, From 4c98b91a9a6f87dd7f183bb2c14a7da6c819ccf7 Mon Sep 17 00:00:00 2001 From: David Bayly Date: Thu, 21 Nov 2024 13:08:00 -0700 Subject: [PATCH 2/2] Removing un-needed comment --- apps/api/src/applicant/external-api.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/api/src/applicant/external-api.service.ts b/apps/api/src/applicant/external-api.service.ts index 27d6dd9b..8bdc3bea 100644 --- a/apps/api/src/applicant/external-api.service.ts +++ b/apps/api/src/applicant/external-api.service.ts @@ -384,7 +384,7 @@ export class ExternalAPIService { ); await Promise.all( applicants.map(async a => { - const query = ` + const audits: { id: string; status_id: string }[] = await manager.query(` SELECT "audit"."id" id, "status"."id" status_id FROM "ien_applicant_status_audit" "audit" INNER JOIN "ien_applicant_status" "status" ON "status"."id" = "audit"."status_id" @@ -392,8 +392,7 @@ export class ExternalAPIService { "audit"."applicant_id" = '${a.applicant_id.toLowerCase()}' AND "status"."category" != 'IEN Recruitment Process' AND "status"."id" NOT IN ('${bccnm_new_statuses.map(status => status.id).join("','")}') - `; - const audits: { id: string; status_id: string }[] = await manager.query(query); + `); if (!audits?.length) return;