3 module.exports = function(sequelize, DataTypes) {
4 var SmsRoom = sequelize.define('SmsRoom', {
6 type: DataTypes.STRING,
12 type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
16 type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE')
22 type: DataTypes.BOOLEAN,
29 if (this.getDataValue('tags')) {
30 tags = this.getDataValue('tags').split(';');
38 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
42 type: DataTypes.STRING
44 openReason: DataTypes.STRING,
52 type: DataTypes.INTEGER
55 type: DataTypes.BOOLEAN,
59 tableName: 'sms_rooms',
60 associate: function(models) {
62 SmsRoom.hasMany(models.SmsMessage);
63 SmsRoom.hasMany(models.SmsRoomStatus, {
64 plural: 'SmsRoomStatuses'
66 SmsRoom.belongsToMany(models.User, {
67 through: 'user_has_sms_rooms'
69 SmsRoom.belongsTo(models.SmsAccount);
70 SmsRoom.addScope('default', {
75 model: models.SmsAccount
77 model: models.SmsMessage,
80 attributes: ['id', 'name', 'fullname', 'email']
84 attributes: ['id', 'name', 'fullname', 'email']
87 SmsRoom.addScope('agent', function(id) {