* Chat Website Model
*/
+const moment = require('moment');
+const satuses = {
+ NEW: ['OPEN', 'CLOSED'],
+ OPEN: ['PENDING', 'CLOSED'],
+ PENDING: ['OPEN', 'CLOSED'],
+ CLOSED: []
+};
module.exports = function(sequelize, DataTypes) {
var MailRoom = sequelize.define('MailRoom', {
type: DataTypes.BOOLEAN,
defaultValue: false
},
+ mailIn: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ mailOut: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
status: {
- type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
- defaultValue: 'NEW'
+ type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
+ defaultValue: 'NEW',
+ set: function(status) {
+ this.setDataValue('status', status);
+
+ switch (status) {
+ case 'NEW':
+ this.setDataValue('arrivedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+ break;
+ case 'CLOSED':
+ this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+ break;
+ default:
+
+ }
+ }
+ },
+ lastEvent: {
+ type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE')
+ },
+ lastEventAt: {
+ type: DataTypes.DATE
+ },
+ deleted: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ waiting: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ tags: {
+ type: DataTypes.TEXT,
+ get: function() {
+ var tags;
+ if (this.getDataValue('tags')) {
+ tags = this.getDataValue('tags').split(';');
+ tags.pop();
+ } else {
+ tags = [];
+ }
+ return tags;
+ },
+ set: function(val) {
+ this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
+ }
+ },
+ disposition: {
+ type: DataTypes.STRING
+ },
+ ParentId: {
+ type: DataTypes.INTEGER
+ },
+ arrivedAt: {
+ type: DataTypes.DATE
+ },
+ closedAt: {
+ type: DataTypes.DATE
}
}, {
tableName: 'mail_rooms',
associate: function(models) {
// BINDING
MailRoom.hasMany(models.MailMessage);
+ MailRoom.hasMany(models.MailRoomStatus, {
+ plural: 'MailRoomStatuses'
+ });
MailRoom.belongsTo(models.MailAccount);
MailRoom.belongsToMany(models.User, {
through: 'user_has_mail_rooms'
model: models.MailAttachment
}, {
model: models.User,
- attributes: ['id', 'name', 'fullname', 'email']
+ attributes: ['id', 'name', 'fullname', 'email', 'userpic']
}]
}, {
model: models.User,
- attributes: ['id', 'name', 'fullname', 'email']
+ attributes: ['id', 'name', 'fullname', 'email', 'userpic']
}]
});
-
- MailRoom.addScope('agent', function(id) {
- return {
- include: [{
- model: models.User,
- where: {
- id: id
- }
- }]
- }
- });
}
});