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', 'CSQUARE'),
defaultValue: 'NEW'
+ },
+ tags: {
+ type: DataTypes.TEXT,
+ get: function() {
+ return this.getDataValue('tags') ? this.getDataValue('tags').split(';') : [];
+ },
+ set: function(val) {
+ this.setDataValue('tags', val.join(';'));
+ }
}
}, {
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
+ }
+ }]
+ }
+ });
}