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

142 lines
1.6 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 project_links = sequelize.define(
'project_links',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
link_type: {
type: DataTypes.ENUM,
values: [
"demo",
"repo",
"article",
"video",
"download",
"other"
],
},
label: {
type: DataTypes.TEXT,
},
url: {
type: DataTypes.TEXT,
},
sort_order: {
type: DataTypes.INTEGER,
},
is_primary: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
project_links.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.project_links.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.project_links.belongsTo(db.users, {
as: 'createdBy',
});
db.project_links.belongsTo(db.users, {
as: 'updatedBy',
});
};
return project_links;
};