more business rules
This commit is contained in:
parent
8d0ee3c604
commit
ade4f62ef8
@ -60,11 +60,21 @@ export class IndustryChangeApplicationService {
|
|||||||
status: {
|
status: {
|
||||||
$in: options.statuses || Object.values(ApplicationStatus),
|
$in: options.statuses || Object.values(ApplicationStatus),
|
||||||
},
|
},
|
||||||
|
objectStatus: ObjectStatus.CURRENT,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getById(id: string) {
|
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) {
|
async create(data: RegisterIndustryChangeApplicationDto, token: string) {
|
||||||
@ -116,6 +126,14 @@ export class IndustryChangeApplicationService {
|
|||||||
current: take(takeMongoObject(getResident), requestedFields),
|
current: take(takeMongoObject(getResident), requestedFields),
|
||||||
requested: take(data, requestedFields),
|
requested: take(data, requestedFields),
|
||||||
status,
|
status,
|
||||||
|
decision:
|
||||||
|
status === ApplicationStatus.APPROVED
|
||||||
|
? {
|
||||||
|
decidedAt: new Date(),
|
||||||
|
decidedBy: 'Automatic',
|
||||||
|
rejectionReason: null,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
submittedAt: new Date(),
|
submittedAt: new Date(),
|
||||||
createdBy: token ?? 'no token provided for testing',
|
createdBy: token ?? 'no token provided for testing',
|
||||||
});
|
});
|
||||||
|
@ -99,10 +99,13 @@ describe('IndustryChangeApplicationController', () => {
|
|||||||
expect(getter.objectStatus).toBe('DELETED');
|
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 appController = app.get(IndustryChangeApplicationController);
|
||||||
const getter = (await appController.getSingle(docID)) as any;
|
const getter = appController.getSingle(docID);
|
||||||
expect(getter.objectStatus).toBe('DELETED');
|
getter.catch((e) => {
|
||||||
|
expect(e.message).toContain('deleted');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user