38235-vm/backend/src/db/models/download_events.js
2026-02-06 02:26:16 +00:00

130 lines
1.8 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 download_events = sequelize.define(
'download_events',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
downloaded_at: {
type: DataTypes.DATE,
},
client_ip: {
type: DataTypes.TEXT,
},
user_agent: {
type: DataTypes.TEXT,
},
referrer_url: {
type: DataTypes.TEXT,
},
success: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
error_message: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
download_events.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.download_events.belongsTo(db.audio_files, {
as: 'audio_file',
foreignKey: {
name: 'audio_fileId',
},
constraints: false,
});
db.download_events.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.download_events.belongsTo(db.users, {
as: 'createdBy',
});
db.download_events.belongsTo(db.users, {
as: 'updatedBy',
});
};
return download_events;
};