5 const crypto = require('crypto');
6 const moment = require('moment');
8 module.exports = function(sequelize, DataTypes) {
10 var FaxRoom = sequelize.define('FaxRoom', {
11 from: DataTypes.STRING,
12 account: DataTypes.STRING,
14 type: DataTypes.INTEGER,
18 type: DataTypes.INTEGER,
22 type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
24 set: function(status) {
25 this.setDataValue('status', status);
29 this.setDataValue('arrivedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
32 this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
40 type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
49 if (this.getDataValue('tags')) {
50 tags = this.getDataValue('tags').split(';');
58 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
62 type: DataTypes.BOOLEAN,
66 type: DataTypes.STRING
68 openReason: DataTypes.STRING,
76 tableName: 'fax_rooms',
78 associate: function(models) {
80 FaxRoom.hasMany(models.FaxMessage);
81 FaxRoom.hasMany(models.FaxRoomStatus, {
82 plural: 'MailRoomStatuses'
84 FaxRoom.belongsTo(models.FaxAccount);
85 FaxRoom.belongsToMany(models.User, {
86 through: 'user_has_fax_rooms'
89 FaxRoom.addScope('default', {
94 model: models.FaxAccount
96 model: models.FaxMessage,
98 model: models.FaxAttachment
101 attributes: ['id', 'name', 'fullname', 'email']
105 attributes: ['id', 'name', 'fullname', 'email']