From ade4f62ef8003791014374c3e3691e4ace1cc0ef Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 7 Dec 2022 08:54:34 +0200 Subject: [PATCH] more business rules --- .../industry-change-application.service.ts | 20 ++++++++++++++++++- .../industry-change-application.spec.ts | 9 ++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/industry-change-application/industry-change-application.service.ts b/src/industry-change-application/industry-change-application.service.ts index 5a766b7..9197291 100644 --- a/src/industry-change-application/industry-change-application.service.ts +++ b/src/industry-change-application/industry-change-application.service.ts @@ -60,11 +60,21 @@ export class IndustryChangeApplicationService { status: { $in: options.statuses || Object.values(ApplicationStatus), }, + objectStatus: ObjectStatus.CURRENT, }); } async getById(id: string) { - return this.applicationModel.findById(id); + const find = await this.applicationModel.findById(id); + if (!find) { + throw new NotFoundException('The application was not found'); + } + + if (find.objectStatus !== ObjectStatus.CURRENT) { + throw new BadRequestException('This application has been deleted.'); + } + + return find; } async create(data: RegisterIndustryChangeApplicationDto, token: string) { @@ -116,6 +126,14 @@ export class IndustryChangeApplicationService { current: take(takeMongoObject(getResident), requestedFields), requested: take(data, requestedFields), status, + decision: + status === ApplicationStatus.APPROVED + ? { + decidedAt: new Date(), + decidedBy: 'Automatic', + rejectionReason: null, + } + : undefined, submittedAt: new Date(), createdBy: token ?? 'no token provided for testing', }); diff --git a/src/industry-change-application/industry-change-application.spec.ts b/src/industry-change-application/industry-change-application.spec.ts index 3f82480..f3c7ea5 100644 --- a/src/industry-change-application/industry-change-application.spec.ts +++ b/src/industry-change-application/industry-change-application.spec.ts @@ -99,10 +99,13 @@ describe('IndustryChangeApplicationController', () => { expect(getter.objectStatus).toBe('DELETED'); }); - it('should request the application and ensure it is deleted', async () => { + it('should request the application and ensure it is deleted', (done) => { const appController = app.get(IndustryChangeApplicationController); - const getter = (await appController.getSingle(docID)) as any; - expect(getter.objectStatus).toBe('DELETED'); + const getter = appController.getSingle(docID); + getter.catch((e) => { + expect(e.message).toContain('deleted'); + done(); + }); }); }); });