39413-vm/backend/src/db/models/builder_projects.js
2026-03-31 07:56:05 +00:00

162 lines
2.0 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 builder_projects = sequelize.define(
'builder_projects',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"in_development",
"submitted",
"approved",
"published",
"archived"
],
},
notes: {
type: DataTypes.TEXT,
},
submitted_at: {
type: DataTypes.DATE,
},
approved_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
builder_projects.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.builder_projects.belongsTo(db.workspaces, {
as: 'workspace',
foreignKey: {
name: 'workspaceId',
},
constraints: false,
});
db.builder_projects.belongsTo(db.users, {
as: 'owner_user',
foreignKey: {
name: 'owner_userId',
},
constraints: false,
});
db.builder_projects.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.builder_projects.belongsTo(db.users, {
as: 'createdBy',
});
db.builder_projects.belongsTo(db.users, {
as: 'updatedBy',
});
};
return builder_projects;
};