Built motion from commit 7afcba0.|0.0.74
[motion.git] / server / models / chat_room.js
1 /**
2  * Chat Website Model
3  */
4
5 var crypto = require('crypto');
6
7 module.exports = function(sequelize, DataTypes) {
8
9         var ChatRoom = sequelize.define('ChatRoom', {
10                 type: DataTypes.ENUM('internal', 'external'),
11                 token: {
12                         type: DataTypes.STRING,
13                         unique: 'token'
14                 },
15                 status: {
16                         type: DataTypes.ENUM('OPEN', 'CLOSED', 'ABANDON'),
17                         defaultValue: 'OPEN'
18                 },
19                 rating: DataTypes.ENUM('good', 'bad'),
20                 ratingMessage: DataTypes.TEXT,
21                 completeReason: DataTypes.ENUM('agent', 'requester'),
22                 ChatVisitorId: {
23                         type: DataTypes.INTEGER,
24                         unique: 'token'
25                 }
26         }, {
27                 tableName: 'chat_rooms',
28                 associate: function(models) {
29                         ChatRoom.hasMany(models.ChatMessage);
30                         ChatRoom.belongsTo(models.ChatVisitor);
31                         ChatRoom.belongsTo(models.ChatWebsite);
32                         ChatRoom.belongsToMany(models.User, {
33                                 through: models.UserHasChatRoom
34                         });
35                 }
36         });
37
38         return ChatRoom;
39 };