2020-03-09 08:00:03 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
module.exports = Self => {
|
2020-09-21 11:24:43 +00:00
|
|
|
require('../methods/role-inherit/sync')(Self);
|
|
|
|
|
2020-03-09 08:00:03 +00:00
|
|
|
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() => {
|
2020-03-09 08:00:03 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|