diff --git a/apps/api/src/applicant/endofjourney.service.ts b/apps/api/src/applicant/endofjourney.service.ts index c60e41960..435f8acec 100644 --- a/apps/api/src/applicant/endofjourney.service.ts +++ b/apps/api/src/applicant/endofjourney.service.ts @@ -251,21 +251,21 @@ export class EndOfJourneyService implements OnModuleInit { `Setting end of journey incomplete: ${STATUS.NOT_PROCEEDING}. Number of lists: ${list.length}`, 'END-OF-JOURNEY', ); - const results = []; - for (const applicant of list) { - // update the end_of_journey_flag and updated_date of the applicant - let query = this.getIncompleteQuery(manager, applicant.applicant_id); - query = this.checkReEngagedStatusForEoJIncompleteQuery(query); + const results = await Promise.all( + list.map(applicant => { + let query = this.getIncompleteQuery(manager, applicant.applicant_id); + query = this.checkReEngagedStatusForEoJIncompleteQuery(query); + + return query + .update('ien_applicants') + .set({ + end_of_journey: END_OF_JOURNEY_FLAG.JOURNEY_INCOMPLETE, + updated_date: dayjs().tz('America/Los_Angeles').toDate(), + }) + .execute(); + }), + ); - const result = await query - .update('ien_applicants') - .set({ - end_of_journey: END_OF_JOURNEY_FLAG.JOURNEY_INCOMPLETE, - updated_date: dayjs().tz('America/Los_Angeles').toDate(), - }) - .execute(); - results.push(result); - } this.logger.log({ results }, 'END-OF-JOURNEY'); }; getIncompleteQuery( @@ -315,25 +315,20 @@ export class EndOfJourneyService implements OnModuleInit { * Event handler for delete re-engaged applicants */ @OnEvent(`${SystemMilestoneEvent.REENGAGED}.*`) - async handleReEngagedDeleteEvent( + async handleReEngagedEvent( payload: IENApplicantStatusAudit, event: SystemMilestoneEvent, + manager: EntityManager, ): Promise { this.logger.log(`Handling re-engaged event: ${event}`, 'END-OF-JOURNEY'); - const connection = this.connection; - if (!connection) { + if (!manager) { this.logger.error('Connection failed', 'END-OF-JOURNEY'); return; } - const queryRunner = connection.createQueryRunner(); - await queryRunner.startTransaction(); - const manager = queryRunner.manager; await this.handleReEngagedForJourneyComplete(manager, payload); await this.handleReEngagedForJourneyIncomplete(manager, payload); - - await queryRunner.commitTransaction(); } private async handleReEngagedForJourneyComplete( diff --git a/apps/api/src/applicant/ienapplicant.service.ts b/apps/api/src/applicant/ienapplicant.service.ts index 7b719a6e1..023ad4d05 100644 --- a/apps/api/src/applicant/ienapplicant.service.ts +++ b/apps/api/src/applicant/ienapplicant.service.ts @@ -348,11 +348,17 @@ export class IENApplicantService { }); // handle update re-engaged if (status_audit.status.status === STATUS.RE_ENGAGED) { - this.eventEmitter.emit( + await this.eventEmitter.emitAsync( SystemMilestoneEvent.CREATE_REENGAGED, status_audit, SystemMilestoneEvent.CREATE_REENGAGED, + manager, ); + // await this.eojService.handleReEngagedEvent( + // status_audit, + // SystemMilestoneEvent.CREATE_REENGAGED, + // manager, + // ); } return status_audit; }); @@ -418,16 +424,17 @@ export class IENApplicantService { [audit.applicant.id], manager, ); - }); - // handle update re-engaged - if (audit.status.status === STATUS.RE_ENGAGED) { - this.eventEmitter.emit( - SystemMilestoneEvent.UPDATE_REENGAGED, - audit, - SystemMilestoneEvent.UPDATE_REENGAGED, - ); - } + // handle update re-engaged + if (audit.status.status === STATUS.RE_ENGAGED) { + await this.eventEmitter.emitAsync( + SystemMilestoneEvent.UPDATE_REENGAGED, + audit, + SystemMilestoneEvent.UPDATE_REENGAGED, + manager, + ); + } + }); return audit; } @@ -463,10 +470,11 @@ export class IENApplicantService { // handle delete re-engaged if (status.status.status === STATUS.RE_ENGAGED) { - this.eventEmitter.emit( + await this.eventEmitter.emitAsync( SystemMilestoneEvent.DELETE_REENGAGED, status, SystemMilestoneEvent.DELETE_REENGAGED, + manager, ); } });