2016-06-19 18:02:32 +08:00
|
|
|
module.exports = (sequelize, Sequelize) => {
|
2016-07-01 00:29:21 +08:00
|
|
|
const Label = sequelize.define('label', {
|
2016-06-30 01:36:32 +08:00
|
|
|
accountId: { type: Sequelize.STRING, allowNull: false },
|
2016-06-30 02:22:38 +08:00
|
|
|
version: Sequelize.INTEGER,
|
2016-06-19 18:02:32 +08:00
|
|
|
name: Sequelize.STRING,
|
|
|
|
role: Sequelize.STRING,
|
|
|
|
}, {
|
|
|
|
classMethods: {
|
2016-07-01 00:29:21 +08:00
|
|
|
associate: ({Message, Thread}) => {
|
|
|
|
Label.belongsToMany(Message, {through: 'message_labels'})
|
|
|
|
Label.belongsToMany(Thread, {through: 'thread_labels'})
|
2016-06-19 18:02:32 +08:00
|
|
|
},
|
|
|
|
},
|
2016-06-23 05:17:45 +08:00
|
|
|
instanceMethods: {
|
|
|
|
toJSON: function toJSON() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
2016-06-30 01:36:32 +08:00
|
|
|
account_id: this.accountId,
|
2016-07-01 00:29:21 +08:00
|
|
|
object: 'label',
|
2016-06-23 05:17:45 +08:00
|
|
|
name: this.role,
|
|
|
|
display_name: this.name,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2016-06-19 18:02:32 +08:00
|
|
|
});
|
|
|
|
|
2016-07-01 00:29:21 +08:00
|
|
|
return Label;
|
2016-06-19 18:02:32 +08:00
|
|
|
};
|