a81f9df193a24b83f572cc6c563ce71ae798aeb8
[motion.git] / server / models / fax_room.js
1 /**
2  * Fax Room Model
3  */
4
5 var crypto = require('crypto');
6
7 module.exports = function(sequelize, DataTypes) {
8
9   var FaxRoom = sequelize.define('FaxRoom', {
10     from: DataTypes.STRING,
11     account: DataTypes.STRING,
12     status: {
13       type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
14       defaultValue: 'NEW'
15     },
16     lastEvent: {
17       type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
18     }
19   }, {
20     tableName: 'fax_rooms',
21     paranoid: true,
22     associate: function(models) {
23       // hasMany relations
24       FaxRoom.hasMany(models.FaxMessage);
25       FaxRoom.belongsTo(models.FaxAccount);
26       FaxRoom.belongsToMany(models.User, {
27         through: 'user_has_fax_rooms'
28       });
29       // SCOPES
30       FaxRoom.addScope('default', {
31         order: [
32           ['createdAt', 'DESC']
33         ],
34         include: [{
35           model: models.FaxAccount
36         }, {
37           model: models.FaxMessage,
38           include: [{
39             model: models.FaxAttachment
40           }, {
41             model: models.User,
42             attributes: ['id', 'name', 'fullname', 'email']
43           }]
44         }, {
45           model: models.User,
46           attributes: ['id', 'name', 'fullname', 'email']
47         }]
48       });
49     }
50   });
51
52   return FaxRoom;
53 };