Dealer_Onboarding_Backend/models/Worknote.js

53 lines
1.3 KiB
JavaScript

const { REQUEST_TYPES } = require('../config/constants');
module.exports = (sequelize, DataTypes) => {
const Worknote = sequelize.define('Worknote', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
requestId: {
type: DataTypes.UUID,
allowNull: false
},
requestType: {
type: DataTypes.ENUM(Object.values(REQUEST_TYPES)),
allowNull: false
},
userId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
content: {
type: DataTypes.TEXT,
allowNull: false
},
isInternal: {
type: DataTypes.BOOLEAN,
defaultValue: true
}
}, {
tableName: 'worknotes',
timestamps: true,
indexes: [
{ fields: ['requestId'] },
{ fields: ['requestType'] },
{ fields: ['userId'] }
]
});
Worknote.associate = (models) => {
Worknote.belongsTo(models.User, {
foreignKey: 'userId',
as: 'author'
});
};
return Worknote;
};