31686/backend/src/db/models/charts.js
2025-05-21 15:23:53 +00:00

60 lines
1.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 charts = sequelize.define(
'charts',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
chart_name: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
charts.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.charts.hasMany(db.file, {
as: 'chart_image',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.charts.getTableName(),
belongsToColumn: 'chart_image',
},
});
db.charts.belongsTo(db.users, {
as: 'createdBy',
});
db.charts.belongsTo(db.users, {
as: 'updatedBy',
});
};
return charts;
};