32587/backend/src/db/models/remittances.js
2025-07-02 16:10:56 +00:00

78 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 remittances = sequelize.define(
'remittances',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
amount: {
type: DataTypes.DECIMAL,
},
date: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
remittances.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.remittances.belongsTo(db.drivers, {
as: 'driver',
foreignKey: {
name: 'driverId',
},
constraints: false,
});
db.remittances.belongsTo(db.tenants, {
as: 'tenant',
foreignKey: {
name: 'tenantId',
},
constraints: false,
});
db.remittances.belongsTo(db.tenants, {
as: 'tenants',
foreignKey: {
name: 'tenantsId',
},
constraints: false,
});
db.remittances.belongsTo(db.users, {
as: 'createdBy',
});
db.remittances.belongsTo(db.users, {
as: 'updatedBy',
});
};
return remittances;
};