(hooks, ...hookArgs)
| 89 | }, |
| 90 | |
| 91 | async runHooks(hooks, ...hookArgs) { |
| 92 | if (!hooks) throw new Error('runHooks requires at least 1 argument'); |
| 93 | |
| 94 | let hookType; |
| 95 | |
| 96 | if (typeof hooks === 'string') { |
| 97 | hookType = hooks; |
| 98 | hooks = getHooks(this, hookType); |
| 99 | |
| 100 | if (this.sequelize) { |
| 101 | hooks = hooks.concat(getHooks(this.sequelize, hookType)); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if (!Array.isArray(hooks)) { |
| 106 | hooks = [hooks]; |
| 107 | } |
| 108 | |
| 109 | // synchronous hooks |
| 110 | if (hookTypes[hookType] && hookTypes[hookType].sync) { |
| 111 | for (let hook of hooks) { |
| 112 | if (typeof hook === 'object') { |
| 113 | hook = hook.fn; |
| 114 | } |
| 115 | |
| 116 | debug(`running hook(sync) ${hookType}`); |
| 117 | hook.apply(this, hookArgs); |
| 118 | } |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | // asynchronous hooks (default) |
| 123 | for (let hook of hooks) { |
| 124 | if (typeof hook === 'object') { |
| 125 | hook = hook.fn; |
| 126 | } |
| 127 | |
| 128 | debug(`running hook ${hookType}`); |
| 129 | await hook.apply(this, hookArgs); |
| 130 | } |
| 131 | }, |
| 132 | |
| 133 | /** |
| 134 | * Add a hook to the model |
no test coverage detected