diff --git a/vehicles/src/modules/case-management/case-management.service.ts b/vehicles/src/modules/case-management/case-management.service.ts index 66b21ecc2..12fb49d88 100644 --- a/vehicles/src/modules/case-management/case-management.service.ts +++ b/vehicles/src/modules/case-management/case-management.service.ts @@ -764,4 +764,73 @@ export class CaseManagementService { } } } + + /** + * The method creates a notification event. + * + * @param currentUser - The current user executing the withdrawal action. + * @param queryRunner - Optional, existing QueryRunner instance used in the transaction process. + * @param caseId - Optional, the ID of the case to be withdrawn. Can be used to retrieve the existing case. + * @param originalCaseId - Optional, the original ID of the case to be withdrawn. Useful in lookup scenarios. + * @param applicationId - Optional, the ID of the permit application associated with the case. + * @param existingCase - Optional, the pre-loaded `Case` entity, if + */ + @LogAsyncMethodExecution() + async createNotificationEvent({ + currentUser, + queryRunner, + caseId, + originalCaseId, + applicationId, + existingCase, + }: { + currentUser: IUserJWT; + queryRunner?: Nullable; + caseId?: Nullable; + originalCaseId?: Nullable; + applicationId?: Nullable; + existingCase?: Nullable; + }): Promise { + let localQueryRunner = true; + ({ localQueryRunner, queryRunner } = await getQueryRunner({ + queryRunner, + dataSource: this.dataSource, + })); + try { + if (!existingCase) { + existingCase = await this.findLatest({ + queryRunner, + caseId, + originalCaseId, + applicationId, + }); + } + + let newEvent = this.createEvent( + existingCase, + CaseEventType.NOTIFICATION, + currentUser, + ); + newEvent = await queryRunner.manager.save(newEvent); + + if (localQueryRunner) { + await queryRunner.commitTransaction(); + } + return await this.classMapper.mapAsync( + newEvent, + CaseEvent, + ReadCaseEvenDto, + ); + } catch (error) { + if (localQueryRunner) { + await queryRunner.rollbackTransaction(); + } + this.logger.error(error); + throw error; + } finally { + if (localQueryRunner) { + await queryRunner.release(); + } + } + } } diff --git a/vehicles/src/modules/permit-application-payment/application/application.service.ts b/vehicles/src/modules/permit-application-payment/application/application.service.ts index 991dee10c..552abcaea 100644 --- a/vehicles/src/modules/permit-application-payment/application/application.service.ts +++ b/vehicles/src/modules/permit-application-payment/application/application.service.ts @@ -1066,13 +1066,22 @@ export class ApplicationService { data: notificationData, }; - void this.dopsService.notificationWithDocumentsFromDops( + await this.dopsService.notificationWithDocumentsFromDops( currentUser, notificationDocument, - true, + false, ); + + await this.caseManagementService.createNotificationEvent({ + currentUser, + applicationId, + queryRunner, + }); + + await queryRunner.commitTransaction(); } } catch (error) { + await queryRunner.rollbackTransaction(); this.logger.error(error); //Swallow Notification error }