38366-vm/backend/src/db/models/wallet_accounts.js
2026-02-11 23:39:30 +00:00

160 lines
2.2 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 wallet_accounts = sequelize.define(
'wallet_accounts',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
wallet_type: {
type: DataTypes.ENUM,
values: [
"viewer_earnings",
"advertiser_prepaid"
],
},
currency: {
type: DataTypes.TEXT,
},
available_balance: {
type: DataTypes.DECIMAL,
},
on_hold_balance: {
type: DataTypes.DECIMAL,
},
status: {
type: DataTypes.ENUM,
values: [
"active",
"locked"
],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
wallet_accounts.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.wallet_accounts.hasMany(db.wallet_transactions, {
as: 'wallet_transactions_wallet_account',
foreignKey: {
name: 'wallet_accountId',
},
constraints: false,
});
db.wallet_accounts.hasMany(db.payments, {
as: 'payments_wallet_account',
foreignKey: {
name: 'wallet_accountId',
},
constraints: false,
});
db.wallet_accounts.hasMany(db.withdrawal_requests, {
as: 'withdrawal_requests_wallet_account',
foreignKey: {
name: 'wallet_accountId',
},
constraints: false,
});
//end loop
db.wallet_accounts.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.wallet_accounts.belongsTo(db.users, {
as: 'createdBy',
});
db.wallet_accounts.belongsTo(db.users, {
as: 'updatedBy',
});
};
return wallet_accounts;
};