5 const moment = require('moment');
7 module.exports = function(sequelize, DataTypes) {
9 var FaxRoom = sequelize.define('FaxRoom', {
10 contact: DataTypes.STRING,
11 account: DataTypes.STRING,
13 type: DataTypes.INTEGER,
17 type: DataTypes.INTEGER,
21 type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
23 set: function(status) {
24 this.setDataValue('status', status);
28 this.setDataValue('arrivedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
31 this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
39 type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
48 if (this.getDataValue('tags')) {
49 tags = this.getDataValue('tags').split(';');
57 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
61 type: DataTypes.BOOLEAN,
65 type: DataTypes.STRING
67 openReason: DataTypes.STRING,
75 tableName: 'fax_rooms',
77 associate: function(models) {
79 FaxRoom.hasMany(models.FaxMessage);
80 FaxRoom.hasMany(models.FaxRoomStatus, {
81 plural: 'MailRoomStatuses'
83 FaxRoom.belongsTo(models.FaxAccount);
84 FaxRoom.belongsToMany(models.User, {
85 through: 'user_has_fax_rooms'
88 FaxRoom.addScope('default', {
93 model: models.FaxAccount
95 model: models.FaxMessage,
97 model: models.FaxAttachment
100 attributes: ['id', 'name', 'fullname', 'email']
104 attributes: ['id', 'name', 'fullname', 'email']