mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: move blocks logic
This commit is contained in:
@@ -38,10 +38,12 @@ export type DeleteResult = {
|
||||
export enum EHook {
|
||||
preCreate = 'preCreate',
|
||||
preUpdate = 'preUpdate',
|
||||
preUpdateMany = 'preUpdateMany',
|
||||
preDelete = 'preDelete',
|
||||
preValidate = 'preValidate',
|
||||
postCreate = 'postCreate',
|
||||
postUpdate = 'postUpdate',
|
||||
postUpdateMany = 'postUpdateMany',
|
||||
postDelete = 'postDelete',
|
||||
postValidate = 'postValidate',
|
||||
}
|
||||
@@ -157,6 +159,19 @@ export abstract class BaseRepository<
|
||||
);
|
||||
});
|
||||
|
||||
hooks?.updateMany.pre.execute(async function () {
|
||||
const query = this as Query<D, D, unknown, T, 'updateMany'>;
|
||||
const criteria = query.getFilter();
|
||||
const updates = query.getUpdate();
|
||||
|
||||
await repository.preUpdateMany(query, criteria, updates);
|
||||
repository.emitter.emit(
|
||||
repository.getEventName(EHook.preUpdateMany),
|
||||
criteria,
|
||||
updates?.['$set'],
|
||||
);
|
||||
});
|
||||
|
||||
hooks?.findOneAndUpdate.post.execute(async function (
|
||||
updated: HydratedDocument<T>,
|
||||
) {
|
||||
@@ -375,6 +390,14 @@ export abstract class BaseRepository<
|
||||
// Nothing ...
|
||||
}
|
||||
|
||||
async preUpdateMany(
|
||||
_query: Query<D, D, unknown, T, 'updateMany'>,
|
||||
_criteria: TFilterQuery<T>,
|
||||
_updates: UpdateWithAggregationPipeline | UpdateQuery<D>,
|
||||
) {
|
||||
// Nothing ...
|
||||
}
|
||||
|
||||
async postUpdate(
|
||||
_query: Query<D, D, unknown, T, 'findOneAndUpdate'>,
|
||||
_updated: T,
|
||||
|
||||
@@ -17,7 +17,7 @@ enum LifecycleOperation {
|
||||
// InsertMany = 'insertMany',
|
||||
// Update = 'update',
|
||||
// UpdateOne = 'updateOne',
|
||||
// UpdateMany = 'updateMany',
|
||||
UpdateMany = 'updateMany',
|
||||
}
|
||||
|
||||
type PreHook = (...args: any[]) => void;
|
||||
@@ -69,7 +69,7 @@ export class LifecycleHookManager {
|
||||
// insertMany: ['pre'],
|
||||
// update: ['pre', 'post'],
|
||||
// updateOne: ['pre', 'post'],
|
||||
// updateMany: ['pre', 'post'],
|
||||
updateMany: ['pre', 'post'],
|
||||
};
|
||||
|
||||
const lifecycleHooks: LifecycleHooks = {} as LifecycleHooks;
|
||||
|
||||
Reference in New Issue
Block a user