Built motion from commit 3594e56.|0.0.120
[motion.git] / server / models / fax_room.js
index 2514438..0e488e7 100644 (file)
@@ -2,20 +2,46 @@
  * 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() {
@@ -38,6 +64,12 @@ module.exports = function(sequelize, DataTypes) {
     },
     disposition: {
       type: DataTypes.STRING
+    },
+    arrivedAt: {
+      type: DataTypes.DATE
+    },
+    closedAt: {
+      type: DataTypes.DATE
     }
   }, {
     tableName: 'fax_rooms',
@@ -45,6 +77,9 @@ module.exports = function(sequelize, DataTypes) {
     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'