31499/backend/src/db/models/thumbnails.js
2025-05-13 21:54:21 +00:00

92 lines
1.9 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 thumbnails = sequelize.define(
'thumbnails',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
thumbnails.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.thumbnails.hasMany(db.reviews, {
as: 'reviews_thumbnail',
foreignKey: {
name: 'thumbnailId',
},
constraints: false,
});
//end loop
db.thumbnails.belongsTo(db.users, {
as: 'creator',
foreignKey: {
name: 'creatorId',
},
constraints: false,
});
db.thumbnails.belongsTo(db.channels, {
as: 'channel',
foreignKey: {
name: 'channelId',
},
constraints: false,
});
db.thumbnails.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.thumbnails.hasMany(db.file, {
as: 'image',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.thumbnails.getTableName(),
belongsToColumn: 'image',
},
});
db.thumbnails.belongsTo(db.users, {
as: 'createdBy',
});
db.thumbnails.belongsTo(db.users, {
as: 'updatedBy',
});
};
return thumbnails;
};