38570-vm/backend/src/db/models/animations.js
2026-02-18 15:49:37 +00:00

145 lines
1.7 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 animations = sequelize.define(
'animations',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
animation_type: {
type: DataTypes.ENUM,
values: [
"motion",
"scroll",
"hover",
"page_transition",
"three_d",
"shader",
"other"
],
},
description: {
type: DataTypes.TEXT,
},
preview_url: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
animations.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.animations.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.animations.hasMany(db.file, {
as: 'source_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.animations.getTableName(),
belongsToColumn: 'source_files',
},
});
db.animations.belongsTo(db.users, {
as: 'createdBy',
});
db.animations.belongsTo(db.users, {
as: 'updatedBy',
});
};
return animations;
};