5 const moment = require('moment');
7 module.exports = function(sequelize, DataTypes) {
8 var MailRoom = sequelize.define('MailRoom', {
9 subject: DataTypes.STRING,
10 from: DataTypes.STRING,
11 account: DataTypes.STRING,
13 type: DataTypes.BOOLEAN,
17 type: DataTypes.INTEGER,
21 type: DataTypes.INTEGER,
25 type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
27 set: function(status) {
28 this.setDataValue('status', status);
30 if (status === 'CLOSED') {
31 this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
36 type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE')
42 type: DataTypes.BOOLEAN,
46 type: DataTypes.BOOLEAN,
53 if (this.getDataValue('tags')) {
54 tags = this.getDataValue('tags').split(';');
62 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
66 type: DataTypes.STRING
72 type: DataTypes.INTEGER
81 tableName: 'mail_rooms',
83 associate: function(models) {
85 MailRoom.hasMany(models.MailMessage);
86 MailRoom.hasMany(models.MailRoomStatus, {
87 plural: 'MailRoomStatuses'
89 MailRoom.belongsTo(models.MailAccount);
90 MailRoom.belongsToMany(models.User, {
91 through: 'user_has_mail_rooms'
94 MailRoom.addScope('default', {
99 model: models.MailAccount
101 model: models.MailMessage,
103 model: models.MailAttachment
106 attributes: ['id', 'name', 'fullname', 'email', 'userpic']
110 attributes: ['id', 'name', 'fullname', 'email', 'userpic']