186 lines
2.4 KiB
JavaScript
186 lines
2.4 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 page_sections = sequelize.define(
|
|
'page_sections',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
section_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"hero",
|
|
|
|
|
|
"features",
|
|
|
|
|
|
"benefits",
|
|
|
|
|
|
"testimonials",
|
|
|
|
|
|
"pricing",
|
|
|
|
|
|
"faq",
|
|
|
|
|
|
"gallery",
|
|
|
|
|
|
"logos",
|
|
|
|
|
|
"contact",
|
|
|
|
|
|
"footer",
|
|
|
|
|
|
"custom_html"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
subtitle: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
content: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
sort_order: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_enabled: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
page_sections.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.page_sections.hasMany(db.section_items, {
|
|
as: 'section_items_page_section',
|
|
foreignKey: {
|
|
name: 'page_sectionId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.page_sections.belongsTo(db.landing_pages, {
|
|
as: 'landing_page',
|
|
foreignKey: {
|
|
name: 'landing_pageId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.page_sections.hasMany(db.file, {
|
|
as: 'images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.page_sections.getTableName(),
|
|
belongsToColumn: 'images',
|
|
},
|
|
});
|
|
|
|
db.page_sections.hasMany(db.file, {
|
|
as: 'attachments',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.page_sections.getTableName(),
|
|
belongsToColumn: 'attachments',
|
|
},
|
|
});
|
|
|
|
|
|
db.page_sections.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.page_sections.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return page_sections;
|
|
};
|
|
|
|
|