3 module.exports = function(sequelize, DataTypes) {
5 var ChatRoom = sequelize.define('ChatRoom', {
6 type: DataTypes.ENUM('internal', 'external', 'group'),
8 type: DataTypes.STRING,
12 type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'ABANDON', 'UNMANAGED'),
15 rating: DataTypes.ENUM('good', 'bad'),
16 ratingMessage: DataTypes.TEXT,
17 completeReason: DataTypes.ENUM('agent', 'requester'),
19 type: DataTypes.INTEGER,
23 type: DataTypes.BOOLEAN,
30 if (this.getDataValue('tags')) {
31 tags = this.getDataValue('tags').split(';');
39 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
43 type: DataTypes.STRING
45 openReason: DataTypes.STRING,
46 contact: DataTypes.STRING,
47 website: DataTypes.STRING
49 tableName: 'chat_rooms',
50 associate: function(models) {
51 ChatRoom.hasMany(models.ChatMessage);
52 ChatRoom.belongsTo(models.ChatVisitor);
53 ChatRoom.belongsTo(models.ChatWebsite);
54 ChatRoom.belongsToMany(models.User, {
55 through: models.UserHasChatRoom
57 ChatRoom.addScope('online', {