34831/backend/src/db/models/financial_entries.js
2025-10-09 14:14:26 +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 financial_entries = sequelize.define(
'financial_entries',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
description: {
type: DataTypes.TEXT,
},
type: {
type: DataTypes.ENUM,
values: ['income', 'expense'],
},
amount: {
type: DataTypes.DECIMAL,
},
due_date: {
type: DataTypes.DATE,
},
status: {
type: DataTypes.ENUM,
values: ['pending', 'paid', 'cancelled', 'deleted'],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
financial_entries.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.financial_entries.belongsTo(db.appointments, {
as: 'appointment',
foreignKey: {
name: 'appointmentId',
},
constraints: false,
});
db.financial_entries.belongsTo(db.users, {
as: 'createdBy',
});
db.financial_entries.belongsTo(db.users, {
as: 'updatedBy',
});
};
return financial_entries;
};