Dealer_Onboarding_Backend/src/database/models/SLAConfiguration.ts

63 lines
1.7 KiB
TypeScript

import { Model, DataTypes, Sequelize } from 'sequelize';
export interface SLAConfigurationAttributes {
id: string;
activityName: string;
ownerRole: string;
tatHours: number;
tatUnit: 'hours' | 'days';
isActive: boolean;
}
export interface SLAConfigurationInstance extends Model<SLAConfigurationAttributes>, SLAConfigurationAttributes { }
export default (sequelize: Sequelize) => {
const SLAConfiguration = sequelize.define<SLAConfigurationInstance>('SLAConfiguration', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
activityName: {
type: DataTypes.STRING,
allowNull: false
},
ownerRole: {
type: DataTypes.STRING,
allowNull: false
},
tatHours: {
type: DataTypes.INTEGER,
allowNull: false
},
tatUnit: {
type: DataTypes.ENUM('hours', 'days'),
defaultValue: 'days'
},
isActive: {
type: DataTypes.BOOLEAN,
defaultValue: true
}
}, {
tableName: 'sla_configurations',
timestamps: true,
indexes: [
{ fields: ['activityName'] },
{ fields: ['ownerRole'] }
]
});
(SLAConfiguration as any).associate = (models: any) => {
SLAConfiguration.hasMany(models.SLAReminder, {
foreignKey: 'slaConfigId',
as: 'reminders'
});
SLAConfiguration.hasMany(models.SLAEscalationConfig, {
foreignKey: 'slaConfigId',
as: 'escalationConfigs'
});
};
return SLAConfiguration;
};