Skip to content

Commit

Permalink
Merge pull request #232 from MuhammadKhalilzadeh/033-nov-9-models-rec…
Browse files Browse the repository at this point in the history
…reation

033 nov 9 models recreation
  • Loading branch information
MuhammadKhalilzadeh authored Nov 10, 2024
2 parents 93a7b8f + b06576f commit be85b86
Show file tree
Hide file tree
Showing 29 changed files with 391 additions and 329 deletions.
12 changes: 6 additions & 6 deletions Servers/controllers/project.ctrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from "express";
import { Project } from "../models/project.model";
const MOCK_DATA_ON = process.env.MOCK_DATA_ON;
const MOCK_DATA_ON = true;

import { STATUS_CODE } from "../utils/statusCode.utils";
import {
Expand All @@ -23,7 +23,7 @@ export async function getAllProjects(
res: Response
): Promise<any> {
try {
if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const projects = getAllMockProjects();

if (projects) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function getProjectById(
try {
const projectId = parseInt(req.params.id);

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const project = getMockProjectById(projectId);

if (project) {
Expand Down Expand Up @@ -86,7 +86,7 @@ export async function createProject(req: Request, res: Response): Promise<any> {
);
}

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const createdProject = createMockProject(newProject);

if (createdProject) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export async function updateProjectById(
);
}

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const project = updateMockProjectById(projectId, updatedProject);

if (project) {
Expand Down Expand Up @@ -153,7 +153,7 @@ export async function deleteProjectById(
try {
const projectId = parseInt(req.params.id);

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const deletedProject = deleteMockProjectById(projectId);

if (deletedProject) {
Expand Down
12 changes: 6 additions & 6 deletions Servers/controllers/question.ctrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from "express";
import { Question } from "../models/question.model";
const MOCK_DATA_ON = process.env.MOCK_DATA_ON;
const MOCK_DATA_ON = true;

import { STATUS_CODE } from "../utils/statusCode.utils";
import {
Expand All @@ -23,7 +23,7 @@ export async function getAllQuestions(
res: Response
): Promise<any> {
try {
if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const questions = getAllMockQuestions();

if (questions) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function getQuestionById(
try {
const questionId = parseInt(req.params.id);

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const question = getMockQuestionById(questionId);

if (question) {
Expand Down Expand Up @@ -95,7 +95,7 @@ export async function createQuestion(
);
}

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const createdQuestion = createMockQuestion(newQuestion);

if (createdQuestion) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function updateQuestionById(
);
}

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const question = updateMockQuestionById(questionId, updatedQuestion);

if (question) {
Expand Down Expand Up @@ -171,7 +171,7 @@ export async function deleteQuestionById(
try {
const questionId = parseInt(req.params.id);

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const deletedQuestion = deleteMockQuestionById(questionId);

if (deletedQuestion) {
Expand Down
12 changes: 6 additions & 6 deletions Servers/controllers/vendorRisk.ctrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from "express";
import { VendorRisk } from "../models/vendorRisk.model";
const MOCK_DATA_ON = process.env.MOCK_DATA_ON;
const MOCK_DATA_ON = true;

import { STATUS_CODE } from "../utils/statusCode.utils";
import {
Expand All @@ -23,7 +23,7 @@ export async function getAllVendorRisks(
res: Response
): Promise<any> {
try {
if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const vendorRisks = getAllMockVendorRisks();

if (vendorRisks) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function getVendorRiskById(
try {
const vendorRiskId = parseInt(req.params.id);

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const vendorRisk = getMockVendorRiskById(vendorRiskId);

if (vendorRisk) {
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function createVendorRisk(
);
}

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const createdVendorRisk = createMockVendorRisk(newVendorRisk);

if (createdVendorRisk) {
Expand Down Expand Up @@ -143,7 +143,7 @@ export async function updateVendorRiskById(
);
}

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const vendorRisk = updateMockVendorRiskById(
vendorRiskId,
updatedVendorRisk
Expand Down Expand Up @@ -178,7 +178,7 @@ export async function deleteVendorRiskById(
try {
const vendorRiskId = parseInt(req.params.id);

if (MOCK_DATA_ON === "true") {
if (MOCK_DATA_ON === true) {
const deletedVendorRisk = deleteMockVendorRiskById(vendorRiskId);

if (deletedVendorRisk) {
Expand Down
165 changes: 165 additions & 0 deletions Servers/driver/autoDriver.driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
import { Assessments } from "../mocks/assessment.mock.data";
import { mockControls } from "../mocks/control.mock.data";
import mockProjects from "../mocks/project.mock.data";
import mockProjectRisks from "../mocks/projectRisks.mock.data";
import { projectScopes } from "../mocks/projectScope.mock.data";
import { questions } from "../mocks/question.mock.data";
import { subcontrols } from "../mocks/subcontrol.mock.data";
import { subtopics } from "../mocks/subtopic.mock.data";
import { topics } from "../mocks/topic.mock.data";
import { users } from "../mocks/users.data";
import { vendors } from "../mocks/vendor.mock.data";
import mockVendorRisks from "../mocks/vendorRisk.mock.data";

import { Assessment } from "../models/assessment.model";
import { Control } from "../models/control.model";
import { Project } from "../models/project.model";
import { ProjectRisk } from "../models/projectRisk.model";
import { ProjectScope } from "../models/projectScope.model";
import { Question } from "../models/question.model";
import { Subcontrol } from "../models/subcontrol.model";
import { Subtopic } from "../models/subtopic.model";
import { Topic } from "../models/topic.model";
import { User } from "../models/user.model";
import { Vendor } from "../models/vendor.model";
import { VendorRisk } from "../models/vendorRisk.model";
Expand All @@ -35,7 +45,12 @@ type TableList = [
TableEntry<Assessment>,
TableEntry<Control>,
TableEntry<Project>,
TableEntry<ProjectRisk>,
TableEntry<ProjectScope>,
TableEntry<Question>,
TableEntry<Subcontrol>,
TableEntry<Subtopic>,
TableEntry<Topic>,
TableEntry<User>,
TableEntry<Vendor>,
TableEntry<VendorRisk>
Expand Down Expand Up @@ -116,6 +131,90 @@ const insertQuery: TableList = [
}')`;
},
},
{
mockData: mockProjectRisks,
tableName: "projectrisks",
createString: `CREATE TABLE projectrisks(
id SERIAL PRIMARY KEY,
project_id integer,
risk_name varchar(255),
risk_owner varchar(255),
ai_lifecycle_phase varchar(255),
risk_description text,
risk_category varchar(255),
impact varchar(255),
assessment_mapping text,
controls_mapping text,
likelihood varchar(255),
severity varchar(255),
risk_level_autocalculated varchar(50) CHECK (risk_level_autocalculated IN ('No risk', 'Low risk', 'Medium risk', 'High risk', 'Very high risk')),
review_notes text,
mitigation_status varchar(255),
current_risk_level varchar(255),
deadline DATE,
mitigation_plan text,
implementation_strategy text,
mitigation_evidence_document text,
likelihood_mitigation varchar(255),
risk_severity varchar(255),
final_risk_level varchar(255),
risk_approval varchar(255),
approval_status varchar(255),
date_of_assessment DATE,
CONSTRAINT projectrisks_project_id_fkey FOREIGN KEY (project_id)
REFERENCES projects(id)
ON DELETE SET NULL
);`,
insertString:
"INSERT INTO projectrisks(project_id, risk_name, risk_owner, ai_lifecycle_phase, risk_description, risk_category, impact, assessment_mapping, controls_mapping, likelihood, severity, risk_level_autocalculated, review_notes, mitigation_status, current_risk_level, deadline, mitigation_plan, implementation_strategy, mitigation_evidence_document, likelihood_mitigation, risk_severity, final_risk_level, risk_approval, approval_status, date_of_assessment) VALUES ",
generateValuesString: function (projectRisk: ProjectRisk) {
return `(${projectRisk.project_id}, '${projectRisk.risk_name}', '${
projectRisk.risk_owner
}', '${projectRisk.ai_lifecycle_phase}', '${
projectRisk.risk_description
}', '${projectRisk.risk_category}', '${projectRisk.impact}', '${
projectRisk.assessment_mapping
}', '${projectRisk.controls_mapping}', '${projectRisk.likelihood}', '${
projectRisk.severity
}', '${projectRisk.risk_level_autocalculated}', '${
projectRisk.review_notes
}', '${projectRisk.mitigation_status}', '${
projectRisk.current_risk_level
}', '${projectRisk.deadline.toISOString().split("T")[0]}', '${
projectRisk.mitigation_plan
}', '${projectRisk.implementation_strategy}', '${
projectRisk.mitigation_evidence_document
}', '${projectRisk.likelihood_mitigation}', '${
projectRisk.risk_severity
}', '${projectRisk.final_risk_level}', '${projectRisk.risk_approval}', '${
projectRisk.approval_status
}', '${projectRisk.date_of_assessment.toISOString().split("T")[0]}')`;
},
},
{
mockData: projectScopes,
tableName: "projectscopes",
createString: `CREATE TABLE projectscopes(
id SERIAL PRIMARY KEY,
assessment_id integer,
describe_ai_environment text,
is_new_ai_technology boolean,
uses_personal_data boolean,
project_scope_documents text,
technology_type varchar(255),
has_ongoing_monitoring boolean,
unintended_outcomes text,
technology_documentation text,
CONSTRAINT projectscopes_assessment_id_fkey FOREIGN KEY (assessment_id)
REFERENCES assessments(id)
ON DELETE SET NULL
);`,
insertString:
"INSERT INTO projectscopes(assessment_id, describe_ai_environment, is_new_ai_technology, uses_personal_data, project_scope_documents, technology_type, has_ongoing_monitoring, unintended_outcomes, technology_documentation) VALUES ",
generateValuesString: function (projectScope: ProjectScope) {
return `(${projectScope.assessmentId}, '${projectScope.describeAiEnvironment}', ${projectScope.isNewAiTechnology}, ${projectScope.usesPersonalData}, '${projectScope.projectScopeDocuments}', '${projectScope.technologyType}', ${projectScope.hasOngoingMonitoring}, '${projectScope.unintendedOutcomes}', '${projectScope.technologyDocumentation}')`;
},
},
{
mockData: questions,
tableName: "questions",
Expand All @@ -139,6 +238,72 @@ const insertQuery: TableList = [
return `(${question.subtopicId}, '${question.questionText}', '${question.answerType}', '${question.dropdownOptions}', ${question.hasFileUpload}, ${question.hasHint}, ${question.isRequired}, '${question.priorityOptions}')`;
},
},
{
mockData: subcontrols,
tableName: "subcontrols",
createString: `CREATE TABLE subcontrols(
id SERIAL PRIMARY KEY,
control_id integer,
status varchar(50) CHECK (status IN ('Waiting', 'In progress', 'Done')),
approver varchar(100),
risk_review varchar(50) CHECK (risk_review IN ('Acceptable risk', 'Residual risk', 'Unacceptable risk')),
owner varchar(100),
reviewer varchar(100),
due_date DATE,
implementation_details text,
evidence text,
attachment text,
feedback text,
CONSTRAINT subcontrols_control_id_fkey FOREIGN KEY (control_id)
REFERENCES controls(id)
ON DELETE SET NULL
);`,
insertString:
"INSERT INTO subcontrols(control_id, status, approver, risk_review, owner, reviewer, due_date, implementation_details, evidence, attachment, feedback) VALUES ",
generateValuesString: function (subcontrol: Subcontrol) {
return `(${subcontrol.controlId}, '${subcontrol.status}', '${
subcontrol.approver
}', '${subcontrol.riskReview}', '${subcontrol.owner}', '${
subcontrol.reviewer
}', '${subcontrol.dueDate.toISOString().split("T")[0]}', '${
subcontrol.implementationDetails
}', '${subcontrol.evidence}', '${subcontrol.attachment}', '${
subcontrol.feedback
}')`;
},
},
{
mockData: subtopics,
tableName: "subtopics",
createString: `CREATE TABLE subtopics(
id SERIAL PRIMARY KEY,
topic_id integer,
name varchar(255),
CONSTRAINT fk_topic FOREIGN KEY (topic_id)
REFERENCES topics (id)
ON DELETE SET NULL
);`,
insertString: "INSERT INTO subtopics(topic_id, name) VALUES ",
generateValuesString: function (subtopic: Subtopic) {
return `(${subtopic.topicId}, '${subtopic.name}')`;
},
},
{
mockData: topics,
tableName: "topics",
createString: `CREATE TABLE topics(
id SERIAL PRIMARY KEY,
assessment_id integer,
name varchar(255),
CONSTRAINT fk_assessment FOREIGN KEY (assessment_id)
REFERENCES assessments (id)
ON DELETE SET NULL
);`,
insertString: "INSERT INTO topics(assessment_id, name) VALUES ",
generateValuesString: function (topic: Topic) {
return `(${topic.assessmentId}, '${topic.title}')`;
},
},
{
mockData: users,
tableName: "users",
Expand Down
8 changes: 8 additions & 0 deletions Servers/endpoints-test/assessment.http.test.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### get all assessments

GET http://localhost:3000/assessments

### get assessment by id

GET http://localhost:3000/assessments/2

8 changes: 8 additions & 0 deletions Servers/endpoints-test/control.http.test.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### get all controls

GET http://localhost:3000/controls

### get control by id

GET http://localhost:3000/controls/2

8 changes: 8 additions & 0 deletions Servers/endpoints-test/project.http.test.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### get all projects

GET http://localhost:3000/projects

### get project by id

GET http://localhost:3000/projects/2

8 changes: 8 additions & 0 deletions Servers/endpoints-test/projectRisk..http.test.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### get all projectRisks

GET http://localhost:3000/projectRisks

### get projectRisk by id

GET http://localhost:3000/projectRisks/2

Loading

0 comments on commit be85b86

Please sign in to comment.