-var _0x566a=["\x63\x72\x79\x70\x74\x6F","\x65\x78\x70\x6F\x72\x74\x73","\x46\x61\x78\x52\x6F\x6F\x6D","\x53\x54\x52\x49\x4E\x47","\x4E\x45\x57","\x4F\x50\x45\x4E","\x50\x45\x4E\x44\x49\x4E\x47","\x53\x4F\x4C\x56\x45\x44","\x43\x4C\x4F\x53\x45\x44","\x66\x61\x78\x5F\x72\x6F\x6F\x6D\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F","\x64\x65\x66\x69\x6E\x65"];var crypto=require(_0x566a[0]);module[_0x566a[1]]=function(_0xd11dx2,_0xd11dx3){var _0xd11dx4=_0xd11dx2[_0x566a[12]](_0x566a[2],{roomId:_0xd11dx3[_0x566a[3]],from:_0xd11dx3[_0x566a[3]],status:_0xd11dx3.ENUM(_0x566a[4],_0x566a[5],_0x566a[6],_0x566a[7],_0x566a[8])},{tableName:_0x566a[9],associate:function(_0xd11dx5){_0xd11dx4[_0x566a[10]](_0xd11dx5.FaxMessage);_0xd11dx4[_0x566a[11]](_0xd11dx5.FaxAccount);_0xd11dx4[_0x566a[11]](_0xd11dx5.User)}});return _0xd11dx4}
\ No newline at end of file
+/**
+ * Fax Room Model
+ */
+
+const crypto = require('crypto');
+const moment = require('moment');
+
+module.exports = function(sequelize, DataTypes) {
+
+ var FaxRoom = sequelize.define('FaxRoom', {
+ from: DataTypes.STRING,
+ account: DataTypes.STRING,
+ faxIn: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ faxOut: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ status: {
+ 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('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
+ },
+ lastEventAt: {
+ type: DataTypes.DATE
+ },
+ 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);
+ }
+ },
+ waiting: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ disposition: {
+ type: DataTypes.STRING
+ },
+ openReason: DataTypes.STRING,
+ arrivedAt: {
+ type: DataTypes.DATE
+ },
+ closedAt: {
+ type: DataTypes.DATE
+ }
+ }, {
+ tableName: 'fax_rooms',
+ paranoid: true,
+ associate: function(models) {
+ // hasMany relations
+ FaxRoom.hasMany(models.FaxMessage);
+ FaxRoom.hasMany(models.FaxRoomStatus, {
+ plural: 'MailRoomStatuses'
+ });
+ FaxRoom.belongsTo(models.FaxAccount);
+ FaxRoom.belongsToMany(models.User, {
+ through: 'user_has_fax_rooms'
+ });
+ // SCOPES
+ FaxRoom.addScope('default', {
+ order: [
+ ['createdAt', 'DESC']
+ ],
+ include: [{
+ model: models.FaxAccount
+ }, {
+ model: models.FaxMessage,
+ include: [{
+ model: models.FaxAttachment
+ }, {
+ model: models.User,
+ attributes: ['id', 'name', 'fullname', 'email']
+ }]
+ }, {
+ model: models.User,
+ attributes: ['id', 'name', 'fullname', 'email']
+ }]
+ });
+ }
+ });
+
+ return FaxRoom;
+};