diff --git a/api/src/utils/generics/base-repository.ts b/api/src/utils/generics/base-repository.ts index 603ccfc9..b8e127f7 100644 --- a/api/src/utils/generics/base-repository.ts +++ b/api/src/utils/generics/base-repository.ts @@ -177,28 +177,30 @@ export abstract class BaseRepository< const query = this as Query; const criteria = query.getFilter(); const updates = query.getUpdate(); - if (updates) { - await repository.preUpdate(query, criteria, updates); - repository.emitter.emit( - repository.getEventName(EHook.preUpdate), - criteria, - updates?.['$set'], - ); + if (!updates) { + throw new Error('Unable to run findOneAndUpdate pre hook'); } + await repository.preUpdate(query, criteria, updates); + repository.emitter.emit( + repository.getEventName(EHook.preUpdate), + criteria, + updates?.['$set'], + ); }); hooks.updateMany.pre.execute(async function () { const query = this as Query; const criteria = query.getFilter(); const updates = query.getUpdate(); - if (updates) { - await repository.preUpdateMany(query, criteria, updates); - repository.emitter.emit( - repository.getEventName(EHook.preUpdateMany), - criteria, - updates?.['$set'], - ); + if (!updates) { + throw new Error('Unable to run run updateMany pre hook'); } + await repository.preUpdateMany(query, criteria, updates); + repository.emitter.emit( + repository.getEventName(EHook.preUpdateMany), + criteria, + updates?.['$set'], + ); }); hooks.updateMany.post.execute(async function (updated: any) {