-'use strict';
+const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
var SmsRoom = sequelize.define('SmsRoom', {
- from: {
+ contact: {
type: DataTypes.STRING,
validate: {
is: /^[\+]?[0-9]+$/
}
},
+ smsIn: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ smsOut: {
+ 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('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE')