226 lines
3.0 KiB
JavaScript
226 lines
3.0 KiB
JavaScript
module.exports = function(sequelize, DataTypes) {
|
|
const projects = sequelize.define(
|
|
'projects',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
slug: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
framework_type: {
|
|
type: DataTypes.STRING,
|
|
|
|
|
|
|
|
},
|
|
|
|
reporting_cycle: {
|
|
type: DataTypes.STRING,
|
|
|
|
|
|
|
|
},
|
|
|
|
indicator_status: {
|
|
type: DataTypes.STRING,
|
|
|
|
|
|
|
|
},
|
|
|
|
primary_outcome: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"planning",
|
|
|
|
|
|
"active",
|
|
|
|
|
|
"paused",
|
|
|
|
|
|
"archived"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
start_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
end_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
repository_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
frontend_stack: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
backend_stack: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
projects.associate = (db) => {
|
|
|
|
db.projects.belongsToMany(db.users, {
|
|
as: 'members',
|
|
foreignKey: {
|
|
name: 'projects_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'projectsMembersUsers',
|
|
});
|
|
|
|
db.projects.belongsToMany(db.users, {
|
|
as: 'members_filter',
|
|
foreignKey: {
|
|
name: 'projects_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'projectsMembersUsers',
|
|
});
|
|
|
|
|
|
/// 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.conversations, {
|
|
as: 'conversations_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.projects.hasMany(db.app_modules, {
|
|
as: 'app_modules_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.projects.hasMany(db.role_permission_rules, {
|
|
as: 'role_permission_rules_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.projects.hasMany(db.audit_logs, {
|
|
as: 'audit_logs_project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'owner',
|
|
foreignKey: {
|
|
name: 'ownerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.projects.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return projects;
|
|
};
|
|
|
|
|