salix/modules/account/back/models/role-inherit.js

23 lines
725 B
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
module.exports = Self => {
2020-09-21 11:24:43 +00:00
require('../methods/role-inherit/sync')(Self);
app.on('started', function() {
let hooks = ['after save', 'after delete'];
for (let hook of hooks) {
2020-09-21 11:24:43 +00:00
Self.observe(hook, async() => {
try {
await Self.rawSql(`
CREATE EVENT account.role_sync
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 SECOND
DO CALL role_sync;
`);
} catch (err) {
if (err.code != 'ER_EVENT_ALREADY_EXISTS') throw err;
}
});
}
});
};