38905-vm/backend/src/db/models/community_links.js
2026-03-01 10:15:50 +00:00

158 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 community_links = sequelize.define(
'community_links',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
link_type: {
type: DataTypes.ENUM,
values: [
"discord",
"telegram",
"twitter",
"website",
"medium",
"github",
"youtube",
"reddit",
"other"
],
},
url: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
sort_order: {
type: DataTypes.INTEGER,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
community_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.community_links.hasMany(db.file, {
as: 'icon_image',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.community_links.getTableName(),
belongsToColumn: 'icon_image',
},
});
db.community_links.belongsTo(db.users, {
as: 'createdBy',
});
db.community_links.belongsTo(db.users, {
as: 'updatedBy',
});
};
return community_links;
};