180 lines
2.3 KiB
JavaScript
180 lines
2.3 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_sections = sequelize.define(
|
|
'project_sections',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
section_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"overview",
|
|
|
|
|
|
"problem",
|
|
|
|
|
|
"process",
|
|
|
|
|
|
"solution",
|
|
|
|
|
|
"results",
|
|
|
|
|
|
"gallery",
|
|
|
|
|
|
"video",
|
|
|
|
|
|
"links",
|
|
|
|
|
|
"credits",
|
|
|
|
|
|
"custom"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
content: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
external_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
sort_order: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_visible: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
project_sections.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_sections.belongsTo(db.projects, {
|
|
as: 'project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.project_sections.hasMany(db.file, {
|
|
as: 'images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.project_sections.getTableName(),
|
|
belongsToColumn: 'images',
|
|
},
|
|
});
|
|
|
|
db.project_sections.hasMany(db.file, {
|
|
as: 'files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.project_sections.getTableName(),
|
|
belongsToColumn: 'files',
|
|
},
|
|
});
|
|
|
|
|
|
db.project_sections.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.project_sections.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return project_sections;
|
|
};
|
|
|
|
|