5 var crypto = require('crypto');
7 module.exports = function(sequelize, DataTypes) {
9 var ChatRoom = sequelize.define('ChatRoom', {
10 type: DataTypes.ENUM('internal', 'external', 'group'),
12 type: DataTypes.STRING,
16 type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'ABANDON', 'UNMANAGED'),
19 rating: DataTypes.ENUM('good', 'bad'),
20 ratingMessage: DataTypes.TEXT,
21 completeReason: DataTypes.ENUM('agent', 'requester'),
23 type: DataTypes.INTEGER,
27 type: DataTypes.BOOLEAN,
34 if (this.getDataValue('tags')) {
35 tags = this.getDataValue('tags').split(';');
43 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
47 type: DataTypes.STRING
49 openReason: DataTypes.STRING
51 tableName: 'chat_rooms',
52 associate: function(models) {
53 ChatRoom.hasMany(models.ChatMessage);
54 ChatRoom.belongsTo(models.ChatVisitor);
55 ChatRoom.belongsTo(models.ChatWebsite);
56 ChatRoom.belongsToMany(models.User, {
57 through: models.UserHasChatRoom
59 ChatRoom.addScope('online', {