Alexandre Bodin 9ddeaffed1 Use a wrapper to cleanup
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-05-04 10:55:07 +02:00

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,
};