38896-vm/backend/src/db/models/exchange_rates.js
2026-03-01 01:42:01 +00:00

122 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 exchange_rates = sequelize.define(
'exchange_rates',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
base_currency: {
type: DataTypes.TEXT,
},
quote_currency: {
type: DataTypes.TEXT,
},
rate: {
type: DataTypes.DECIMAL,
},
effective_at: {
type: DataTypes.DATE,
},
provider: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
exchange_rates.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.exchange_rates.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.exchange_rates.belongsTo(db.users, {
as: 'createdBy',
});
db.exchange_rates.belongsTo(db.users, {
as: 'updatedBy',
});
};
return exchange_rates;
};