39895-vm/backend/src/db/models/payment_methods.js
2026-05-04 20:37:17 +00:00

135 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 payment_methods = sequelize.define(
'payment_methods',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
method_type: {
type: DataTypes.ENUM,
values: [
"cash",
"bank_transfer",
"mobile_payment",
"zelle",
"card",
"other"
],
},
details: {
type: DataTypes.TEXT,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
payment_methods.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.payment_methods.hasMany(db.payments, {
as: 'payments_payment_method',
foreignKey: {
name: 'payment_methodId',
},
constraints: false,
});
//end loop
db.payment_methods.belongsTo(db.users, {
as: 'createdBy',
});
db.payment_methods.belongsTo(db.users, {
as: 'updatedBy',
});
};
return payment_methods;
};