Dealer_Onboarding_Backend/models/FinancePayment.js

76 lines
2.0 KiB
JavaScript

const { PAYMENT_TYPES, PAYMENT_STATUS } = require('../config/constants');
module.exports = (sequelize, DataTypes) => {
const FinancePayment = sequelize.define('FinancePayment', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
applicationId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'applications',
key: 'id'
}
},
paymentType: {
type: DataTypes.ENUM(Object.values(PAYMENT_TYPES)),
allowNull: false
},
amount: {
type: DataTypes.DECIMAL(15, 2),
allowNull: false
},
paymentStatus: {
type: DataTypes.ENUM(Object.values(PAYMENT_STATUS)),
defaultValue: PAYMENT_STATUS.PENDING
},
transactionId: {
type: DataTypes.STRING,
allowNull: true
},
paymentDate: {
type: DataTypes.DATE,
allowNull: true
},
verifiedBy: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'users',
key: 'id'
}
},
verificationDate: {
type: DataTypes.DATE,
allowNull: true
},
remarks: {
type: DataTypes.TEXT,
allowNull: true
}
}, {
tableName: 'finance_payments',
timestamps: true,
indexes: [
{ fields: ['applicationId'] },
{ fields: ['paymentStatus'] }
]
});
FinancePayment.associate = (models) => {
FinancePayment.belongsTo(models.Application, {
foreignKey: 'applicationId',
as: 'application'
});
FinancePayment.belongsTo(models.User, {
foreignKey: 'verifiedBy',
as: 'verifier'
});
};
return FinancePayment;
};