-var _0xa733=["\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(_0xa733[0]);module[_0xa733[1]]=function(_0x62cdx2,_0x62cdx3){var _0x62cdx4=_0x62cdx2[_0xa733[15]](_0xa733[2],{type:_0x62cdx3.ENUM(_0xa733[3],_0xa733[4]),token:{type:_0x62cdx3[_0xa733[5]],unique:_0xa733[6]},status:{type:_0x62cdx3.ENUM(_0xa733[7],_0xa733[8]),defaultValue:_0xa733[7]},ChatVisitorId:{type:_0x62cdx3[_0xa733[9]],unique:_0xa733[6]}},{tableName:_0xa733[10],associate:function(_0x62cdx5){_0x62cdx4[_0xa733[11]](_0x62cdx5.ChatMessage);_0x62cdx4[_0xa733[12]](_0x62cdx5.ChatVisitor);_0x62cdx4[_0xa733[12]](_0x62cdx5.ChatWebsite);_0x62cdx4[_0xa733[14]](_0x62cdx5.User,{through:_0x62cdx5[_0xa733[13]]})}});return _0x62cdx4}
\ 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;
+};