mirror of
https://github.com/strapi/strapi.git
synced 2025-07-25 09:56:53 +00:00
21 lines
458 B
JavaScript
21 lines
458 B
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
|
|
const executeHook = async (hook, model, ...args) => {
|
|
if (_.has(model, hook)) {
|
|
await model[hook](...args);
|
|
}
|
|
};
|
|
|
|
const executeBeforeHook = (hook, model, ...args) =>
|
|
executeHook(`before${_.upperFirst(hook)}`, model, ...args);
|
|
|
|
const executeAfterHook = (hook, model, ...args) =>
|
|
executeHook(`after${_.upperFirst(hook)}`, model, ...args);
|
|
|
|
module.exports = {
|
|
executeBeforeHook,
|
|
executeAfterHook,
|
|
};
|