2016-06-24 07:28:51 +08:00
|
|
|
const PubsubConnector = require('./pubsub-connector')
|
2016-06-29 06:35:35 +08:00
|
|
|
const MessageTypes = require('./message-types')
|
2016-06-24 07:28:51 +08:00
|
|
|
|
|
|
|
module.exports = (db, sequelize) => {
|
|
|
|
sequelize.addHook("afterCreate", ({dataValues, $modelOptions}) => {
|
2016-07-01 04:25:13 +08:00
|
|
|
if ($modelOptions.name.singular === 'account') {
|
2016-06-24 07:28:51 +08:00
|
|
|
PubsubConnector.broadcastClient().lpushAsync('accounts:unclaimed', dataValues.id);
|
2016-07-01 04:25:13 +08:00
|
|
|
PubsubConnector.notifyAccount(dataValues.id, {
|
|
|
|
type: MessageTypes.ACCOUNT_CREATED,
|
2016-06-29 06:35:35 +08:00
|
|
|
});
|
2016-06-24 07:28:51 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
sequelize.addHook("afterUpdate", ({dataValues, $modelOptions}) => {
|
2016-07-01 04:25:13 +08:00
|
|
|
if ($modelOptions.name.singular === 'account') {
|
|
|
|
PubsubConnector.notifyAccount(dataValues.id, {
|
2016-06-30 02:22:38 +08:00
|
|
|
type: MessageTypes.ACCOUNT_UPDATED,
|
2016-06-29 06:35:35 +08:00
|
|
|
});
|
2016-06-24 07:28:51 +08:00
|
|
|
}
|
|
|
|
})
|
2016-07-12 07:56:18 +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
|
|
|
}
|