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}) => {
|
|
|
|
if ($modelOptions.name.singular === 'Account') {
|
|
|
|
PubsubConnector.broadcastClient().lpushAsync('accounts:unclaimed', dataValues.id);
|
2016-06-29 06:35:35 +08:00
|
|
|
PubsubConnector.notify({
|
|
|
|
accountId: dataValues.id,
|
|
|
|
type: MessageTypes.ACCOUNT_UPDATED
|
|
|
|
});
|
2016-06-24 07:28:51 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
sequelize.addHook("afterUpdate", ({dataValues, $modelOptions}) => {
|
|
|
|
if ($modelOptions.name.singular === 'Account') {
|
2016-06-29 06:35:35 +08:00
|
|
|
PubsubConnector.notify({
|
|
|
|
accountId: dataValues.id,
|
|
|
|
type: MessageTypes.ACCOUNT_UPDATED
|
|
|
|
});
|
2016-06-24 07:28:51 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
// TODO delete account from redis
|
|
|
|
// sequelize.addHook("afterDelete", ({dataValues, $modelOptions}) => {
|
|
|
|
// })
|
|
|
|
}
|