mirror of
https://github.com/strapi/strapi.git
synced 2025-07-19 07:02:26 +00:00
21 lines
583 B
JavaScript
21 lines
583 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const _ = require('lodash');
|
||
|
|
||
|
const executeLifecycleHook = async (lifecycle, model, ...args) => {
|
||
|
if (_.has(model, `lifecycles.${lifecycle}`)) {
|
||
|
await model.lifecycles[lifecycle](...args);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const executeBeforeLifecycleHook = (lifecycle, model, ...args) =>
|
||
|
executeLifecycleHook(`before${_.upperFirst(lifecycle)}`, model, ...args);
|
||
|
|
||
|
const executeAfterLifecycleHook = (lifecycle, model, ...args) =>
|
||
|
executeLifecycleHook(`after${_.upperFirst(lifecycle)}`, model, ...args);
|
||
|
|
||
|
module.exports = {
|
||
|
executeBeforeLifecycleHook,
|
||
|
executeAfterLifecycleHook,
|
||
|
};
|