module.exports = function(sequelize, DataTypes) {
var SmsRoom = sequelize.define('SmsRoom', {
- from: DataTypes.INTEGER,
+ from: {
+ type: DataTypes.STRING,
+ validate: {
+ is: /^[\+]?[0-9]+$/
+ }
+ },
status: {
- type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED'),
+ type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
defaultValue: 'NEW'
+ },
+ tags: {
+ type: DataTypes.TEXT,
+ get: function() {
+ var tags;
+ if (this.getDataValue('tags')) {
+ tags = this.getDataValue('tags').split(';');
+ tags.pop();
+ } else {
+ tags = [];
+ }
+ return tags;
+ },
+ set: function(val) {
+ this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
+ }
+ },
+ disposition: {
+ type: DataTypes.STRING
+ },
+ ParentId: {
+ type: DataTypes.INTEGER
+ },
+ voiceSource: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
}
}, {
tableName: 'sms_rooms',
associate: function(models) {
// BINDING
SmsRoom.hasMany(models.SmsMessage);
- SmsRoom.belongsTo(models.User);
-
+ SmsRoom.belongsToMany(models.User, {
+ through: 'user_has_sms_rooms'
+ });
SmsRoom.belongsTo(models.SmsAccount);
SmsRoom.addScope('default', {
order: [
attributes: ['id', 'name', 'fullname', 'email']
}]
});
+ SmsRoom.addScope('agent', function(id) {
+ return {
+ include: [{
+ model: models.User,
+ where: {
+ id: id
+ }
+ }]
+ }
+ });
}