Skip to content

Commit

Permalink
Create notification event
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot committed Sep 9, 2024
1 parent 0a0655e commit 1da4384
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
69 changes: 69 additions & 0 deletions vehicles/src/modules/case-management/case-management.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryRunner>;
caseId?: Nullable<number>;
originalCaseId?: Nullable<number>;
applicationId?: Nullable<string>;
existingCase?: Nullable<Case>;
}): Promise<ReadCaseEvenDto> {
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<CaseEvent>(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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1da4384

Please sign in to comment.