Dealer_Onboarding_Backend/src/database/models/SLAEscalationConfig.ts

63 lines
1.7 KiB
TypeScript

import { Model, DataTypes, Sequelize } from 'sequelize';
export interface SLAEscalationConfigAttributes {
id: string;
slaConfigId: string;
level: number;
timeValue: number;
timeUnit: 'hours' | 'days';
notifyEmail: string;
}
export interface SLAEscalationConfigInstance extends Model<SLAEscalationConfigAttributes>, SLAEscalationConfigAttributes { }
export default (sequelize: Sequelize) => {
const SLAEscalationConfig = sequelize.define<SLAEscalationConfigInstance>('SLAEscalationConfig', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
slaConfigId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'sla_configurations',
key: 'id'
}
},
level: {
type: DataTypes.INTEGER,
allowNull: false
},
timeValue: {
type: DataTypes.INTEGER,
allowNull: false
},
timeUnit: {
type: DataTypes.ENUM('hours', 'days'),
allowNull: false
},
notifyEmail: {
type: DataTypes.STRING,
allowNull: false,
validate: { isEmail: true }
}
}, {
tableName: 'sla_config_escalations',
timestamps: true,
indexes: [
{ fields: ['slaConfigId'] }
]
});
(SLAEscalationConfig as any).associate = (models: any) => {
SLAEscalationConfig.belongsTo(models.SLAConfiguration, {
foreignKey: 'slaConfigId',
as: 'slaConfig'
});
};
return SLAEscalationConfig;
};