2026-05-28 15:12:46 +00:00

140 lines
1.8 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 charges = sequelize.define(
'charges',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
charge_reference: {
type: DataTypes.TEXT,
},
amount: {
type: DataTypes.DECIMAL,
},
charged_on: {
type: DataTypes.DATE,
},
charge_status: {
type: DataTypes.ENUM,
values: [
"authorized",
"captured",
"voided",
"refunded",
"failed"
],
},
description: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
charges.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.charges.belongsTo(db.customers, {
as: 'customer',
foreignKey: {
name: 'customerId',
},
constraints: false,
});
db.charges.hasMany(db.file, {
as: 'receipt_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.charges.getTableName(),
belongsToColumn: 'receipt_files',
},
});
db.charges.belongsTo(db.users, {
as: 'createdBy',
});
db.charges.belongsTo(db.users, {
as: 'updatedBy',
});
};
return charges;
};