mirror of
https://github.com/hexastack/hexabot
synced 2025-02-24 21:34:31 +00:00
fix: throw when no updates has been provided
This commit is contained in:
parent
fa282fb77b
commit
4972011dfd
@ -177,28 +177,30 @@ export abstract class BaseRepository<
|
|||||||
const query = this as Query<D, D, unknown, T, 'findOneAndUpdate'>;
|
const query = this as Query<D, D, unknown, T, 'findOneAndUpdate'>;
|
||||||
const criteria = query.getFilter();
|
const criteria = query.getFilter();
|
||||||
const updates = query.getUpdate();
|
const updates = query.getUpdate();
|
||||||
if (updates) {
|
if (!updates) {
|
||||||
await repository.preUpdate(query, criteria, updates);
|
throw new Error('Unable to run findOneAndUpdate pre hook');
|
||||||
repository.emitter.emit(
|
|
||||||
repository.getEventName(EHook.preUpdate),
|
|
||||||
criteria,
|
|
||||||
updates?.['$set'],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
await repository.preUpdate(query, criteria, updates);
|
||||||
|
repository.emitter.emit(
|
||||||
|
repository.getEventName(EHook.preUpdate),
|
||||||
|
criteria,
|
||||||
|
updates?.['$set'],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.updateMany.pre.execute(async function () {
|
hooks.updateMany.pre.execute(async function () {
|
||||||
const query = this as Query<D, D, unknown, T, 'updateMany'>;
|
const query = this as Query<D, D, unknown, T, 'updateMany'>;
|
||||||
const criteria = query.getFilter();
|
const criteria = query.getFilter();
|
||||||
const updates = query.getUpdate();
|
const updates = query.getUpdate();
|
||||||
if (updates) {
|
if (!updates) {
|
||||||
await repository.preUpdateMany(query, criteria, updates);
|
throw new Error('Unable to run run updateMany pre hook');
|
||||||
repository.emitter.emit(
|
|
||||||
repository.getEventName(EHook.preUpdateMany),
|
|
||||||
criteria,
|
|
||||||
updates?.['$set'],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
await repository.preUpdateMany(query, criteria, updates);
|
||||||
|
repository.emitter.emit(
|
||||||
|
repository.getEventName(EHook.preUpdateMany),
|
||||||
|
criteria,
|
||||||
|
updates?.['$set'],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.updateMany.post.execute(async function (updated: any) {
|
hooks.updateMany.post.execute(async function (updated: any) {
|
||||||
|
Loading…
Reference in New Issue
Block a user