37830-vm/backend/src/db/models/projects.js
2026-01-26 11:10:34 +00:00

262 lines
3.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 projects = sequelize.define(
'projects',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"generating",
"ready",
"deployed",
"archived"
],
},
visibility: {
type: DataTypes.ENUM,
values: [
"private",
"public"
],
},
tech_stack: {
type: DataTypes.ENUM,
values: [
"React/Next.js",
"Node.js",
"Supabase",
"Firebase",
"TailwindCSS"
],
},
repo_url: {
type: DataTypes.TEXT,
},
demo_url: {
type: DataTypes.TEXT,
},
created_on: {
type: DataTypes.DATE,
},
updated_on: {
type: DataTypes.DATE,
},
start_date: {
type: DataTypes.DATE,
},
end_date: {
type: DataTypes.DATE,
},
is_production: {
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.users, {
as: 'collaborators',
foreignKey: {
name: 'projects_collaboratorsId',
},
constraints: false,
through: 'projectsCollaboratorsUsers',
});
db.projects.belongsToMany(db.users, {
as: 'collaborators_filter',
foreignKey: {
name: 'projects_collaboratorsId',
},
constraints: false,
through: 'projectsCollaboratorsUsers',
});
/// 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.prompts, {
as: 'prompts_project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.projects.hasMany(db.deployments, {
as: 'deployments_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: 'owner',
foreignKey: {
name: 'ownerId',
},
constraints: false,
});
db.projects.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.projects.belongsTo(db.users, {
as: 'createdBy',
});
db.projects.belongsTo(db.users, {
as: 'updatedBy',
});
};
return projects;
};