40193-vm/backend/src/db/models/section_items.js
2026-06-04 13:56:56 +00:00

132 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 section_items = sequelize.define(
'section_items',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
link_label: {
type: DataTypes.TEXT,
},
link_url: {
type: DataTypes.TEXT,
},
sort_order: {
type: DataTypes.INTEGER,
},
is_highlighted: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
section_items.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.section_items.belongsTo(db.page_sections, {
as: 'page_section',
foreignKey: {
name: 'page_sectionId',
},
constraints: false,
});
db.section_items.hasMany(db.file, {
as: 'images',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.section_items.getTableName(),
belongsToColumn: 'images',
},
});
db.section_items.belongsTo(db.users, {
as: 'createdBy',
});
db.section_items.belongsTo(db.users, {
as: 'updatedBy',
});
};
return section_items;
};