* Fax Room Model
*/
-var crypto = require('crypto');
+const crypto = require('crypto');
+const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
var FaxRoom = sequelize.define('FaxRoom', {
from: DataTypes.STRING,
account: DataTypes.STRING,
+ faxIn: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ faxOut: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
status: {
- type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
- defaultValue: 'NEW'
+ type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
+ defaultValue: 'NEW',
+ set: function(status) {
+ this.setDataValue('status', status);
+
+ switch (status) {
+ case 'NEW':
+ this.setDataValue('arrivedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+ break;
+ case 'CLOSED':
+ this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+ break;
+ default:
+
+ }
+ }
},
lastEvent: {
type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
},
+ lastEventAt: {
+ type: DataTypes.DATE
+ },
tags: {
type: DataTypes.TEXT,
get: function() {
},
disposition: {
type: DataTypes.STRING
+ },
+ openReason: DataTypes.STRING,
+ arrivedAt: {
+ type: DataTypes.DATE
+ },
+ closedAt: {
+ type: DataTypes.DATE
}
}, {
tableName: 'fax_rooms',
associate: function(models) {
// hasMany relations
FaxRoom.hasMany(models.FaxMessage);
+ FaxRoom.hasMany(models.FaxRoomStatus, {
+ plural: 'MailRoomStatuses'
+ });
FaxRoom.belongsTo(models.FaxAccount);
FaxRoom.belongsToMany(models.User, {
through: 'user_has_fax_rooms'