fix: throw if no updates has been provided to updateOne

This commit is contained in:
abdou6666 2024-12-20 08:57:21 +01:00
parent 4972011dfd
commit aaa24656d3

View File

@ -488,22 +488,24 @@ export abstract class BaseRepository<
);
const filterCriteria = query.getFilter();
const queryUpdates = query.getUpdate();
if (queryUpdates) {
await this.preUpdateValidate(filterCriteria, queryUpdates);
this.emitter.emit(
this.getEventName(EHook.preUpdateValidate),
filterCriteria,
queryUpdates,
);
await this.postUpdateValidate(filterCriteria, queryUpdates);
this.emitter.emit(
this.getEventName(EHook.postUpdateValidate),
filterCriteria,
queryUpdates,
);
if (!queryUpdates) {
throw new Error('updateOne() query updates are not undefined');
}
await this.preUpdateValidate(filterCriteria, queryUpdates);
this.emitter.emit(
this.getEventName(EHook.preUpdateValidate),
filterCriteria,
queryUpdates,
);
await this.postUpdateValidate(filterCriteria, queryUpdates);
this.emitter.emit(
this.getEventName(EHook.postUpdateValidate),
filterCriteria,
queryUpdates,
);
return await this.executeOne(query, this.cls);
}