33666/backend/src/db/models/orders.js
2025-08-28 02:23:29 +00:00

77 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 orders = sequelize.define(
'orders',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
order_value: {
type: DataTypes.DECIMAL,
},
order_date: {
type: DataTypes.DATE,
},
is_profitable: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
orders.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.orders.belongsTo(db.strategies, {
as: 'strategy',
foreignKey: {
name: 'strategyId',
},
constraints: false,
});
db.orders.belongsTo(db.trading_pairs, {
as: 'trading_pair',
foreignKey: {
name: 'trading_pairId',
},
constraints: false,
});
db.orders.belongsTo(db.users, {
as: 'createdBy',
});
db.orders.belongsTo(db.users, {
as: 'updatedBy',
});
};
return orders;
};