39477-vm/backend/src/db/models/exchange_rates.js
2026-04-05 01:41:33 +00:00

118 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 exchange_rates = sequelize.define(
'exchange_rates',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
rate_date: {
type: DataTypes.DATE,
},
usd_to_syp: {
type: DataTypes.DECIMAL,
},
is_locked: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
note: {
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.stores, {
as: 'store',
foreignKey: {
name: 'storeId',
},
constraints: false,
});
db.exchange_rates.belongsTo(db.users, {
as: 'set_by_user',
foreignKey: {
name: 'set_by_userId',
},
constraints: false,
});
db.exchange_rates.belongsTo(db.users, {
as: 'createdBy',
});
db.exchange_rates.belongsTo(db.users, {
as: 'updatedBy',
});
};
return exchange_rates;
};