2025-06-11 16:43:37 +00:00

80 lines
1.5 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function (sequelize, DataTypes) {
const loans = sequelize.define(
'loans',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
amount: {
type: DataTypes.DECIMAL,
},
status: {
type: DataTypes.ENUM,
values: ['Pending', 'Approved', 'Rejected'],
},
application_date: {
type: DataTypes.DATE,
},
approval_date: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
loans.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.loans.belongsTo(db.members, {
as: 'member',
foreignKey: {
name: 'memberId',
},
constraints: false,
});
db.loans.belongsTo(db.branches, {
as: 'branches',
foreignKey: {
name: 'branchesId',
},
constraints: false,
});
db.loans.belongsTo(db.users, {
as: 'createdBy',
});
db.loans.belongsTo(db.users, {
as: 'updatedBy',
});
};
return loans;
};