38727-vm/backend/src/db/models/balances.js
2026-02-24 00:53:51 +00:00

116 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 balances = sequelize.define(
'balances',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
available_btc: {
type: DataTypes.DECIMAL,
},
pending_btc: {
type: DataTypes.DECIMAL,
},
lifetime_earned_btc: {
type: DataTypes.DECIMAL,
},
lifetime_withdrawn_btc: {
type: DataTypes.DECIMAL,
},
as_of_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
balances.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.balances.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.balances.belongsTo(db.users, {
as: 'createdBy',
});
db.balances.belongsTo(db.users, {
as: 'updatedBy',
});
};
return balances;
};