add .exec() to mongo queries

This commit is contained in:
Evert Prants 2022-12-07 09:10:04 +02:00
parent ade4f62ef8
commit b6a92325a7
2 changed files with 15 additions and 11 deletions

View File

@ -55,17 +55,19 @@ export class IndustryChangeApplicationService {
throw new NotFoundException('Resident not found'); throw new NotFoundException('Resident not found');
} }
return this.applicationModel.find({ return this.applicationModel
.find({
residentSub: options.residentSub, residentSub: options.residentSub,
status: { status: {
$in: options.statuses || Object.values(ApplicationStatus), $in: options.statuses || Object.values(ApplicationStatus),
}, },
objectStatus: ObjectStatus.CURRENT, objectStatus: ObjectStatus.CURRENT,
}); })
.exec();
} }
async getById(id: string) { async getById(id: string) {
const find = await this.applicationModel.findById(id); const find = await this.applicationModel.findById(id).exec();
if (!find) { if (!find) {
throw new NotFoundException('The application was not found'); throw new NotFoundException('The application was not found');
} }
@ -151,7 +153,7 @@ export class IndustryChangeApplicationService {
} }
async markDeleted(id: string, token: string) { async markDeleted(id: string, token: string) {
const findApplication = await this.applicationModel.findById(id); const findApplication = await this.applicationModel.findById(id).exec();
if (!findApplication) { if (!findApplication) {
throw new NotFoundException('Application was not found'); throw new NotFoundException('Application was not found');

View File

@ -16,10 +16,12 @@ export class ResidentService {
} }
public async getResidentBySub(sub: string): Promise<Resident> { public async getResidentBySub(sub: string): Promise<Resident> {
return this.residentModel.findOne({ sub }); return this.residentModel.findOne({ sub }).exec();
} }
public async save(resident: Partial<Resident>): Promise<Resident> { public async save(resident: Partial<Resident>): Promise<Resident> {
return this.residentModel.findOneAndUpdate({ sub: resident.sub }, resident); return this.residentModel
.findOneAndUpdate({ sub: resident.sub }, resident)
.exec();
} }
} }