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

198 lines
2.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 mining_accounts = sequelize.define(
'mining_accounts',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
label: {
type: DataTypes.TEXT,
},
provider_type: {
type: DataTypes.ENUM,
values: [
"pool",
"self_hosted",
"cloud_provider"
],
},
provider_name: {
type: DataTypes.TEXT,
},
api_base_url: {
type: DataTypes.TEXT,
},
api_key: {
type: DataTypes.TEXT,
},
api_secret: {
type: DataTypes.TEXT,
},
is_default: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
status: {
type: DataTypes.ENUM,
values: [
"connected",
"disconnected",
"error",
"disabled"
],
},
last_sync_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
mining_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.mining_accounts.hasMany(db.miners, {
as: 'miners_mining_account',
foreignKey: {
name: 'mining_accountId',
},
constraints: false,
});
db.mining_accounts.hasMany(db.payouts, {
as: 'payouts_mining_account',
foreignKey: {
name: 'mining_accountId',
},
constraints: false,
});
db.mining_accounts.hasMany(db.api_jobs, {
as: 'api_jobs_mining_account',
foreignKey: {
name: 'mining_accountId',
},
constraints: false,
});
//end loop
db.mining_accounts.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.mining_accounts.belongsTo(db.users, {
as: 'createdBy',
});
db.mining_accounts.belongsTo(db.users, {
as: 'updatedBy',
});
};
return mining_accounts;
};