55fcef79704c2d937d243eac248359feb7a4d863
[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                 name: DataTypes.STRING,
12                 token: {
13                         type: DataTypes.STRING,
14                         unique: true
15                 },
16                 // jobId: {
17                 //      type: DataTypes.INTEGER,
18                 //      unique: true
19                 // },
20                 status: {
21                         type: DataTypes.ENUM('pending', 'open', 'close'),
22                         defaultValue: 'pending'
23                 },
24                 // participants: DataTypes.TEXT
25         }, {
26                 tableName: 'chat_rooms',
27                 associate: function(models) {
28                         ChatRoom.hasMany(models.ChatMessage);
29                         ChatRoom.belongsTo(models.ChatVisitor);
30                         ChatRoom.belongsTo(models.ChatWebsite);
31                         ChatRoom.belongsToMany(models.User, {
32                                 through: models.UserHasChatRoom
33                         });
34                 }
35         });
36
37         return ChatRoom;
38 };