-'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')
+ },
+ lastEventAt: {
+ type: DataTypes.DATE
+ },
+ waiting: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
},
tags: {
type: DataTypes.TEXT,
disposition: {
type: DataTypes.STRING
},
+ openReason: DataTypes.STRING,
+ arrivedAt: {
+ type: DataTypes.DATE
+ },
+ closedAt: {
+ type: DataTypes.DATE
+ },
ParentId: {
type: DataTypes.INTEGER
},
- source: DataTypes.STRING
+ voiceSource: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ }
}, {
tableName: 'sms_rooms',
associate: function(models) {
// BINDING
SmsRoom.hasMany(models.SmsMessage);
+ SmsRoom.hasMany(models.SmsRoomStatus, {
+ plural: 'SmsRoomStatuses'
+ });
SmsRoom.belongsToMany(models.User, {
through: 'user_has_sms_rooms'
});