-var _0xcc96=["\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(_0xcc96[0]);module[_0xcc96[1]]=function(_0x2e2dx2,_0x2e2dx3){var _0x2e2dx4=_0x2e2dx2[_0xcc96[12]](_0xcc96[2],{roomId:_0x2e2dx3[_0xcc96[3]],from:_0x2e2dx3[_0xcc96[3]],status:_0x2e2dx3.ENUM(_0xcc96[4],_0xcc96[5],_0xcc96[6],_0xcc96[7],_0xcc96[8])},{tableName:_0xcc96[9],associate:function(_0x2e2dx5){_0x2e2dx4[_0xcc96[10]](_0x2e2dx5.FaxMessage);_0x2e2dx4[_0xcc96[11]](_0x2e2dx5.FaxAccount);_0x2e2dx4[_0xcc96[11]](_0x2e2dx5.User);}});return _0x2e2dx4;};
\ No newline at end of file
+/**
+ * Fax Room Model
+ */
+
+var crypto = require('crypto');
+
+module.exports = function(sequelize, DataTypes) {
+
+ var FaxRoom = sequelize.define('FaxRoom', {
+ from: DataTypes.STRING,
+ account: DataTypes.STRING,
+ status: {
+ type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
+ defaultValue: 'NEW'
+ },
+ lastEvent: {
+ type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
+ },
+ 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);
+ }
+ },
+ }, {
+ tableName: 'fax_rooms',
+ paranoid: true,
+ associate: function(models) {
+ // hasMany relations
+ FaxRoom.hasMany(models.FaxMessage);
+ 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;
+};