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

27 lines
867 B
JavaScript
Raw Normal View History

2016-06-24 07:28:51 +08:00
const PubsubConnector = require('./pubsub-connector')
const MessageTypes = require('./message-types')
2016-06-24 07:28:51 +08:00
module.exports = (db, sequelize) => {
sequelize.addHook("afterCreate", ({dataValues, $modelOptions}) => {
if ($modelOptions.name.singular === 'account') {
PubsubConnector.notifyAccount(dataValues.id, {
type: MessageTypes.ACCOUNT_CREATED,
});
2016-06-24 07:28:51 +08:00
}
})
sequelize.addHook("afterUpdate", ({dataValues, $modelOptions}) => {
if ($modelOptions.name.singular === 'account') {
PubsubConnector.notifyAccount(dataValues.id, {
type: MessageTypes.ACCOUNT_UPDATED,
});
2016-06-24 07:28:51 +08:00
}
})
sequelize.addHook("afterDestroy", ({dataValues, $modelOptions}) => {
if ($modelOptions.name.singular === 'account') {
PubsubConnector.notifyAccount(dataValues.id, {
type: MessageTypes.ACCOUNT_DELETED,
});
}
})
2016-06-24 07:28:51 +08:00
}