-var _0xd535=["\x65\x78\x70\x6F\x72\x74\x73","\x4D\x61\x69\x6C\x52\x6F\x6F\x6D","\x53\x54\x52\x49\x4E\x47","\x42\x4F\x4F\x4C\x45\x41\x4E","\x4E\x45\x57","\x4F\x50\x45\x4E","\x43\x4C\x4F\x53\x45\x44","\x6D\x61\x69\x6C\x5F\x72\x6F\x6F\x6D\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F","\x75\x73\x65\x72\x5F\x68\x61\x73\x5F\x6D\x61\x69\x6C\x5F\x72\x6F\x6F\x6D\x73","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F\x4D\x61\x6E\x79","\x64\x65\x66\x61\x75\x6C\x74","\x63\x72\x65\x61\x74\x65\x64\x41\x74","\x44\x45\x53\x43","\x4D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74","\x4D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65","\x4D\x61\x69\x6C\x41\x74\x74\x61\x63\x68\x6D\x65\x6E\x74","\x55\x73\x65\x72","\x69\x64","\x6E\x61\x6D\x65","\x66\x75\x6C\x6C\x6E\x61\x6D\x65","\x65\x6D\x61\x69\x6C","\x61\x64\x64\x53\x63\x6F\x70\x65","\x61\x67\x65\x6E\x74","\x64\x65\x66\x69\x6E\x65"];module[_0xd535[0]]=function(_0xacafx1,_0xacafx2){var _0xacafx3=_0xacafx1[_0xd535[25]](_0xd535[1],{subject:_0xacafx2[_0xd535[2]],from:_0xacafx2[_0xd535[2]],attachment:{type:_0xacafx2[_0xd535[3]],defaultValue:false},status:{type:_0xacafx2.ENUM(_0xd535[4],_0xd535[5],_0xd535[6]),defaultValue:_0xd535[4]}},{tableName:_0xd535[7],paranoid:true,associate:function(_0xacafx4){_0xacafx3[_0xd535[8]](_0xacafx4.MailMessage);_0xacafx3[_0xd535[9]](_0xacafx4.MailAccount);_0xacafx3[_0xd535[11]](_0xacafx4.User,{through:_0xd535[10]});_0xacafx3[_0xd535[23]](_0xd535[12],{order:[[_0xd535[13],_0xd535[14]]],include:[{model:_0xacafx4[_0xd535[15]]},{model:_0xacafx4[_0xd535[16]],include:[{model:_0xacafx4[_0xd535[17]]},{model:_0xacafx4[_0xd535[18]],attributes:[_0xd535[19],_0xd535[20],_0xd535[21],_0xd535[22]]}]},{model:_0xacafx4[_0xd535[18]],attributes:[_0xd535[19],_0xd535[20],_0xd535[21],_0xd535[22]]}]});_0xacafx3[_0xd535[23]](_0xd535[24],function(_0xacafx5){return {include:[{model:_0xacafx4[_0xd535[18]],where:{id:_0xacafx5}}]}})}});return _0xacafx3}
\ No newline at end of file
+/**
+ * Chat Website Model
+ */
+
+const moment = require('moment');
+
+module.exports = function(sequelize, DataTypes) {
+ var MailRoom = sequelize.define('MailRoom', {
+ subject: DataTypes.STRING,
+ from: DataTypes.STRING,
+ account: DataTypes.STRING,
+ attachment: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ mailIn: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ mailOut: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ status: {
+ type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
+ defaultValue: 'NEW',
+ set: function(status) {
+ this.setDataValue('status', status);
+
+ if (status === 'CLOSED') {
+ this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+ }
+ }
+ },
+ 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
+ },
+ deletedAt: {
+ type: DataTypes.DATE
+ },
+ ParentId: {
+ type: DataTypes.INTEGER
+ },
+ arrivedAt: {
+ type: DataTypes.DATE
+ },
+ closedAt: {
+ type: DataTypes.DATE
+ }
+ }, {
+ tableName: 'mail_rooms',
+ paranoid: true,
+ 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'
+ });
+ // SCOPES
+ MailRoom.addScope('default', {
+ order: [
+ ['createdAt', 'DESC']
+ ],
+ include: [{
+ model: models.MailAccount
+ }, {
+ model: models.MailMessage,
+ include: [{
+ model: models.MailAttachment
+ }, {
+ model: models.User,
+ attributes: ['id', 'name', 'fullname', 'email', 'userpic']
+ }]
+ }, {
+ model: models.User,
+ attributes: ['id', 'name', 'fullname', 'email', 'userpic']
+ }]
+ });
+ }
+ });
+
+ return MailRoom;
+};