-var _0x5a79=["\x63\x72\x79\x70\x74\x6F","\x65\x78\x70\x6F\x72\x74\x73","\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x69\x6E\x74\x65\x72\x6E\x61\x6C","\x65\x78\x74\x65\x72\x6E\x61\x6C","\x53\x54\x52\x49\x4E\x47","\x74\x6F\x6B\x65\x6E","\x4F\x50\x45\x4E","\x43\x4C\x4F\x53\x45\x44","\x49\x4E\x54\x45\x47\x45\x52","\x63\x68\x61\x74\x5F\x72\x6F\x6F\x6D\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F","\x55\x73\x65\x72\x48\x61\x73\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F\x4D\x61\x6E\x79","\x64\x65\x66\x69\x6E\x65"];var crypto=require(_0x5a79[0]);module[_0x5a79[1]]=function(_0xdd2ax2,_0xdd2ax3){var _0xdd2ax4=_0xdd2ax2[_0x5a79[15]](_0x5a79[2],{type:_0xdd2ax3.ENUM(_0x5a79[3],_0x5a79[4]),token:{type:_0xdd2ax3[_0x5a79[5]],unique:_0x5a79[6]},status:{type:_0xdd2ax3.ENUM(_0x5a79[7],_0x5a79[8]),defaultValue:_0x5a79[7]},ChatVisitorId:{type:_0xdd2ax3[_0x5a79[9]],unique:_0x5a79[6]}},{tableName:_0x5a79[10],associate:function(_0xdd2ax5){_0xdd2ax4[_0x5a79[11]](_0xdd2ax5.ChatMessage);_0xdd2ax4[_0x5a79[12]](_0xdd2ax5.ChatVisitor);_0xdd2ax4[_0x5a79[12]](_0xdd2ax5.ChatWebsite);_0xdd2ax4[_0x5a79[14]](_0xdd2ax5.User,{through:_0xdd2ax5[_0x5a79[13]]})}});return _0xdd2ax4}
\ No newline at end of file
+'use strict';
+
+module.exports = function(sequelize, DataTypes) {
+
+ var ChatRoom = sequelize.define('ChatRoom', {
+ type: DataTypes.ENUM('internal', 'external', 'group'),
+ token: {
+ type: DataTypes.STRING,
+ unique: 'token'
+ },
+ status: {
+ type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'ABANDON', 'UNMANAGED'),
+ defaultValue: 'NEW'
+ },
+ rating: DataTypes.ENUM('good', 'bad'),
+ ratingMessage: DataTypes.TEXT,
+ completeReason: DataTypes.ENUM('agent', 'requester'),
+ ChatVisitorId: {
+ type: DataTypes.INTEGER,
+ unique: 'token'
+ },
+ 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
+ },
+ openReason: DataTypes.STRING,
+ contact: DataTypes.STRING,
+ website: DataTypes.STRING
+ }, {
+ tableName: 'chat_rooms',
+ associate: function(models) {
+ ChatRoom.hasMany(models.ChatMessage);
+ ChatRoom.belongsTo(models.ChatVisitor);
+ ChatRoom.belongsTo(models.ChatWebsite);
+ ChatRoom.belongsToMany(models.User, {
+ through: models.UserHasChatRoom
+ });
+ ChatRoom.addScope('online', {
+ where: {
+ $and: [{
+ type: 'external'
+ }, {
+ $or: [{
+ status: 'CLOSED'
+ }, {
+ status: 'OPEN'
+ }]
+ }]
+ }
+ });
+ }
+ });
+
+ return ChatRoom;
+};