const app = require('vn-loopback/server/server'); module.exports = Self => { require('../methods/role-inherit/sync')(Self); app.on('started', function() { let hooks = ['after save', 'after delete']; for (let hook of hooks) { 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; } }); } }); };