37788-vm/backend/src/db/models/payments.js
2026-01-25 06:14:00 +00:00

143 lines
1.6 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 payments = sequelize.define(
'payments',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
paymentDate: {
type: DataTypes.DATE,
},
amount: {
type: DataTypes.DECIMAL,
},
method: {
type: DataTypes.ENUM,
values: [
"cash",
"bank_transfer",
"credit_card",
"other"
],
},
reference: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
payments.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.payments.belongsTo(db.tenants, {
as: 'tenantId',
foreignKey: {
name: 'tenantIdId',
},
constraints: false,
});
db.payments.belongsTo(db.invoices, {
as: 'invoiceId',
foreignKey: {
name: 'invoiceIdId',
},
constraints: false,
});
db.payments.belongsTo(db.users, {
as: 'createdBy',
});
db.payments.belongsTo(db.users, {
as: 'updatedBy',
});
};
return payments;
};