Skip to content

Commit f1e3a30

Browse files
Merge pull request #2203 from bluewave-labs/hp-sep-23-fix-project-delete-bug
Fix project delete bug
2 parents c3be15a + ce14a6b commit f1e3a30

5 files changed

Lines changed: 15 additions & 11 deletions

File tree

Servers/controllers/user.ctrl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ async function getAllUsers(req: Request, res: Response): Promise<any> {
4848

4949
if (users && users.length > 0) {
5050
logStructured('successful', `found ${users.length} users`, 'getAllUsers', 'user.ctrl.ts');
51-
console.log('✅ Sending successful response with users:', users.map((user) => user.toSafeJSON()));
5251
return res
5352
.status(200)
5453
.json(STATUS_CODE[200](users.map((user) => user.toSafeJSON())));

Servers/infrastructure.layer/driver/autoDriver.driver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export async function insertMockData(
168168
risk_approval: users[1].id!,
169169
approval_status: "In Progress",
170170
date_of_assessment: new Date(Date.now()),
171+
projects: [project.id!],
172+
frameworks: [2, 3], // ISO frameworks
171173
},
172174
tenant,
173175
transaction

Servers/utils/project.utils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export const updateProjectUpdatedByIdQuery = async (
304304
byTable:
305305
| "controls"
306306
| "answers"
307-
| "projectrisks"
307+
// | "projectrisks"
308308
| "vendors"
309309
| "subclauses"
310310
| "annexcategories"
@@ -316,9 +316,9 @@ export const updateProjectUpdatedByIdQuery = async (
316316
const queryMap = {
317317
controls: `SELECT pf.project_id as id FROM "${tenant}".controls_eu c JOIN "${tenant}".projects_frameworks pf ON pf.id = c.projects_frameworks_id WHERE c.id = :id;`,
318318
answers: `SELECT pf.project_id as id FROM "${tenant}".assessments a JOIN "${tenant}".answers_eu ans ON ans.assessment_id = a.id JOIN "${tenant}".projects_frameworks pf ON pf.id = a.projects_frameworks_id WHERE ans.id = :id;`,
319-
projectrisks: `SELECT p.id FROM
320-
"${tenant}".projects p JOIN "${tenant}".projectrisks pr ON p.id = pr.project_id
321-
WHERE pr.id = :id;`,
319+
// projectrisks: `SELECT p.id FROM
320+
// "${tenant}".projects p JOIN "${tenant}".projectrisks pr ON p.id = pr.project_id
321+
// WHERE pr.id = :id;`,
322322
vendors: `SELECT project_id as id FROM "${tenant}".vendors_projects WHERE vendor_id = :id;`,
323323
subclauses: `SELECT pf.project_id as id FROM "${tenant}".subclauses_iso sc JOIN "${tenant}".projects_frameworks pf ON pf.id = sc.projects_frameworks_id WHERE sc.id = :id;`,
324324
annexcategories: `SELECT pf.project_id as id FROM "${tenant}".annexcategories_iso a JOIN "${tenant}".projects_frameworks pf ON pf.id = a.projects_frameworks_id WHERE a.id = :id;`,
@@ -480,7 +480,8 @@ export const deleteHelper = async (
480480
let childIds: any = {};
481481
if (
482482
childTableName !== "projects_members" &&
483-
childTableName !== "projects_frameworks"
483+
childTableName !== "projects_frameworks" &&
484+
childTableName !== "projects_risks"
484485
) {
485486
if (childTableName === "vendors") {
486487
childIds = await sequelize.query(
@@ -555,7 +556,7 @@ export const deleteProjectByIdQuery = async (
555556
},
556557
},
557558
{ files: { foreignKey: "project_id", model: FileModel } },
558-
{ projectrisks: { foreignKey: "project_id", model: RiskModel } },
559+
{ projects_risks: { foreignKey: "project_id", model: RiskModel } },
559560
{
560561
projects_members: {
561562
foreignKey: "project_id",
@@ -604,7 +605,7 @@ export const calculateProjectRisks = async (
604605
risk_level_autocalculated: string;
605606
count: string;
606607
}>(
607-
`SELECT risk_level_autocalculated, count(*) AS count FROM "${tenant}".projectrisks WHERE project_id = :project_id GROUP BY risk_level_autocalculated`,
608+
`SELECT risk_level_autocalculated, count(*) AS count FROM "${tenant}".risks r JOIN "${tenant}".projects_risks pr ON r.id = pr.risk_id WHERE pr.project_id = :project_id GROUP BY risk_level_autocalculated`,
608609
{
609610
replacements: { project_id },
610611
type: QueryTypes.SELECT,

Servers/utils/reporting.utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import { IProjectsMembers } from "../domain.layer/interfaces/i.projectMember";
2323
export const getProjectRisksReportQuery = async (projectId: number, tenant: string) => {
2424
const query = `
2525
SELECT
26-
risk.*,
26+
risk.*,
27+
pr.project_id AS project_id,
2728
u.name AS risk_owner_name,
2829
u.surname AS risk_owner_surname
29-
FROM "${tenant}".projectrisks risk
30+
FROM "${tenant}".risks risk
31+
JOIN "${tenant}".projects_risks pr ON risk.id = pr.risk_id
3032
LEFT JOIN public.users u ON risk.risk_owner = u.id
3133
WHERE project_id = :project_id
3234
ORDER BY created_at DESC, id ASC

Servers/utils/user.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export const deleteUserByIdQuery = async (
330330
// fields: ["approver", "owner", "reviewer"],
331331
// },
332332
{
333-
table: "projectrisks",
333+
table: "risks",
334334
model: RiskModel,
335335
fields: ["risk_owner", "risk_approval"],
336336
},

0 commit comments

Comments
 (0)