Mailspring/packages/nylas-core/hook-account-crud.js

19 lines
685 B
JavaScript
Raw Normal View History

2016-06-24 07:28:51 +08:00
const PubsubConnector = require('./pubsub-connector')
module.exports = (db, sequelize) => {
sequelize.addHook("afterCreate", ({dataValues, $modelOptions}) => {
if ($modelOptions.name.singular === 'Account') {
PubsubConnector.broadcastClient().lpushAsync('accounts:unclaimed', dataValues.id);
PubsubConnector.notifyAccountChange(dataValues.id);
2016-06-24 07:28:51 +08:00
}
})
sequelize.addHook("afterUpdate", ({dataValues, $modelOptions}) => {
if ($modelOptions.name.singular === 'Account') {
PubsubConnector.notifyAccountChange(dataValues.id);
}
})
// TODO delete account from redis
// sequelize.addHook("afterDelete", ({dataValues, $modelOptions}) => {
// })
}