255 lines
3.8 KiB
JavaScript
255 lines
3.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 projects = sequelize.define(
|
|
'projects',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
slug: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"published",
|
|
|
|
|
|
"archived"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
short_summary: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
case_study: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
demo_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
repository_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
start_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
end_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_featured: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
sort_weight: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
projects.associate = (db) => {
|
|
|
|
db.projects.belongsToMany(db.skills, {
|
|
as: 'skills',
|
|
foreignKey: {
|
|
name: 'projects_skillsId',
|
|
},
|
|
constraints: false,
|
|
through: 'projectsSkillsSkills',
|
|
});
|
|
|
|
db.projects.belongsToMany(db.skills, {
|
|
as: 'skills_filter',
|
|
foreignKey: {
|
|
name: 'projects_skillsId',
|
|
},
|
|
constraints: false,
|
|
through: 'projectsSkillsSkills',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.projects.hasMany(db.project_links, {
|
|
as: 'project_links_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.projects.hasMany(db.project_technology_tags, {
|
|
as: 'project_technology_tags_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.projects.hasMany(db.animations, {
|
|
as: 'animations_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.projects.hasMany(db.testimonials, {
|
|
as: 'testimonials_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'author_user',
|
|
foreignKey: {
|
|
name: 'author_userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.projects.hasMany(db.file, {
|
|
as: 'cover_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.projects.getTableName(),
|
|
belongsToColumn: 'cover_images',
|
|
},
|
|
});
|
|
|
|
db.projects.hasMany(db.file, {
|
|
as: 'gallery_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.projects.getTableName(),
|
|
belongsToColumn: 'gallery_images',
|
|
},
|
|
});
|
|
|
|
db.projects.hasMany(db.file, {
|
|
as: 'asset_files',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.projects.getTableName(),
|
|
belongsToColumn: 'asset_files',
|
|
},
|
|
});
|
|
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return projects;
|
|
};
|
|
|
|
|