[feat] add actions to notifications (add/del/update)
This commit is contained in:
56
server/migrations/20190927160148-new_notification.js
Normal file
56
server/migrations/20190927160148-new_notification.js
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
const { notification: Notification } = require('../api/models')
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
|
||||
// remove all notifications
|
||||
await Notification.destroy({where: []})
|
||||
|
||||
// add `action` field to notification
|
||||
try {
|
||||
await queryInterface.addColumn('notifications', 'action', {
|
||||
type: Sequelize.ENUM,
|
||||
values: ['Create', 'Update', 'Delete']
|
||||
})
|
||||
} catch {}
|
||||
|
||||
// modify values of `type` field
|
||||
try {
|
||||
await queryInterface.removeColumn('notifications', 'type')
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
await queryInterface.addColumn('notifications', 'type', {
|
||||
type: Sequelize.ENUM,
|
||||
values: ['mail', 'admin_email', 'ap']
|
||||
})
|
||||
} catch {}
|
||||
|
||||
await queryInterface.addIndex('notifications', {
|
||||
unique: true,
|
||||
fields: ['action', 'type' ]
|
||||
})
|
||||
|
||||
// add AP notifications
|
||||
await Notification.create({ action: 'Create', type: 'ap', filters: { is_visible: true } })
|
||||
await Notification.create({ action: 'Update', type: 'ap', filters: { is_visible: true } })
|
||||
await Notification.create({ action: 'Delete', type: 'ap', filters: { is_visible: true } })
|
||||
|
||||
// send anon events via email to admin
|
||||
await Notification.create({ action: 'Create', type: 'admin_email', filters: { is_visible: false } })
|
||||
|
||||
return true
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return Promise.resolve()
|
||||
/*
|
||||
Add reverting commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.dropTable('users');
|
||||
*/
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user