Built motion from commit 1243baf.|0.0.90
[motion.git] / server / models / chat_queue.js
1 'use strict';
2
3 module.exports = function(sequelize, DataTypes) {
4
5   var ChatQueue = sequelize.define('ChatQueue', {
6     name: {
7       type: DataTypes.STRING,
8       unique: true,
9       allowNull: false,
10       validate: {
11         notEmpty: true,
12       }
13     },
14     description: {
15       type: DataTypes.STRING,
16     },
17     timeout: {
18       type: DataTypes.INTEGER,
19     },
20     strategy: {
21       type: DataTypes.ENUM('rrmemory', 'beepall')
22     }
23   }, {
24     tableName: 'chat_queues',
25     associate: function(models) {
26       // hasMany relations
27       ChatQueue.belongsToMany(models.User, {
28         through: models.UserHasChatQueue
29       });
30
31       ChatQueue.belongsToMany(models.User, {
32         through: models.UserHasChatQueuePermit,
33         as: 'PChatQueues'
34       });
35
36       //SCOPES
37       ChatQueue.addScope('default', {
38         include: [{
39           model: models.User,
40           attributes: ['id', 'name', 'fullname', 'email', 'online', 'lastLoginAt', 'chatPause', 'pauseType']
41         }]
42       });
43     }
44   });
45
46   return ChatQueue;
47 };