195 lines
2.8 KiB
JavaScript
195 lines
2.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,
|
|
|
|
|
|
|
|
},
|
|
|
|
summary: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"draft",
|
|
|
|
|
|
"published",
|
|
|
|
|
|
"archived"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
location: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
started_on: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
completed_on: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_featured: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
projects.associate = (db) => {
|
|
|
|
db.projects.belongsToMany(db.services, {
|
|
as: 'services',
|
|
foreignKey: {
|
|
name: 'projects_servicesId',
|
|
},
|
|
constraints: false,
|
|
through: 'projectsServicesServices',
|
|
});
|
|
|
|
db.projects.belongsToMany(db.services, {
|
|
as: 'services_filter',
|
|
foreignKey: {
|
|
name: 'projects_servicesId',
|
|
},
|
|
constraints: false,
|
|
through: 'projectsServicesServices',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
db.projects.hasMany(db.file, {
|
|
as: 'before_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.projects.getTableName(),
|
|
belongsToColumn: 'before_images',
|
|
},
|
|
});
|
|
|
|
db.projects.hasMany(db.file, {
|
|
as: 'after_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.projects.getTableName(),
|
|
belongsToColumn: 'after_images',
|
|
},
|
|
});
|
|
|
|
db.projects.hasMany(db.file, {
|
|
as: 'gallery_images',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.projects.getTableName(),
|
|
belongsToColumn: 'gallery_images',
|
|
},
|
|
});
|
|
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return projects;
|
|
};
|
|
|
|
|