Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

040 Nov 5 Add Swagger for Vendors #206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Servers/controllers/vendor.ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,20 @@ export async function getVendorById(req: Request, res: Response): Promise<any> {

export async function createVendor(req: Request, res: Response): Promise<any> {
try {
const { name, description } = req.body;
const {
name,
type,
description,
website,
contact_person,
assignee,
status,
review_result,
reviewer,
review_date,
review_status,
risk_status
} = req.body;
Comment on lines +72 to +85
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify variable access pattern.

The destructuring of request body fields is redundant since the values are later accessed directly via req.body. Either use the destructured variables consistently or remove the destructuring.

-    const {
-      name,
-      type,
-      description,
-      website,
-      contact_person,
-      assignee,
-      status,
-      review_result,
-      reviewer,
-      review_date,
-      review_status,
-      risk_status
-    } = req.body;
+    const vendorData = {
+      name: req.body.name,
+      description: req.body.description,
+      type: req.body.type,
+      website: req.body.website,
+      contact_person: req.body.contact_person,
+      assignee: req.body.assignee,
+      status: req.body.status,
+      review_result: req.body.review_result,
+      reviewer: req.body.reviewer,
+      review_date: req.body.review_date,
+      review_status: req.body.review_status,
+      risk_status: req.body.risk_status
+    };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const {
name,
type,
description,
website,
contact_person,
assignee,
status,
review_result,
reviewer,
review_date,
review_status,
risk_status
} = req.body;
const vendorData = {
name: req.body.name,
description: req.body.description,
type: req.body.type,
website: req.body.website,
contact_person: req.body.contact_person,
assignee: req.body.assignee,
status: req.body.status,
review_result: req.body.review_result,
reviewer: req.body.reviewer,
review_date: req.body.review_date,
review_status: req.body.review_status,
risk_status: req.body.risk_status
};


if (!name || !description) {
return res
Expand Down
20 changes: 8 additions & 12 deletions Servers/driver/autoDriver.driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,22 @@ const insertQuery: TableList = [
createString: `CREATE TABLE vendors(
id SERIAL PRIMARY KEY,
name varchar(255) NOT NULL,
project_id integer,
type varchar(100),
description text,
website varchar(255),
contact_person varchar(100),
assignee varchar(100),
status varchar(100),
review_result varchar(50),
review_status varchar(50),
reviewer_id integer,
review_date timestamp,
risk_status varchar(50),
CONSTRAINT vendors_reviewer_id_fkey FOREIGN KEY (reviewer_id)
REFERENCES users(id)
ON DELETE SET NULL,
CONSTRAINT vendors_project_id_fkey FOREIGN KEY (project_id)
REFERENCES projects(id)
ON DELETE SET NULL
reviewer varchar(50),
review_date varchar(50),
risk_status varchar(50)
Comment on lines +139 to +149
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Schema design improvements needed for the vendors table.

Consider the following improvements to the table structure:

  1. Add NOT NULL constraints for critical fields (type, status)
  2. Add foreign key constraints for user references
  3. Use proper date type for review_date
  4. Add indexes for frequently queried fields

Apply these changes to improve data integrity and query performance:

-      type varchar(100),
+      type varchar(100) NOT NULL,
       description text,
       website varchar(255),
       contact_person varchar(100),
-      assignee varchar(100),
+      assignee integer,
-      status varchar(100),
+      status varchar(100) NOT NULL,
       review_result varchar(50),
       review_status varchar(50),
-      reviewer varchar(50),
+      reviewer integer,
-      review_date varchar(50),
+      review_date timestamp,
-      risk_status varchar(50)
+      risk_status varchar(50),
+      CONSTRAINT fk_assignee FOREIGN KEY (assignee)
+        REFERENCES users(id)
+        ON DELETE SET NULL,
+      CONSTRAINT fk_reviewer FOREIGN KEY (reviewer)
+        REFERENCES users(id)
+        ON DELETE SET NULL

Committable suggestion skipped: line range outside the PR's diff.

);`,
insertString:
"INSERT INTO vendors(name, project_id, description, website, contact_person, review_result, review_status, reviewer_id, review_date, risk_status) VALUES ",
"INSERT INTO vendors(name, type, description, website, contact_person, assignee, status, review_result, review_status, reviewer, review_date, risk_status) VALUES ",
generateValuesString: function (vendor: Vendor) {
return `(${vendor.id}, '${vendor.name}', '${vendor.type}', '${vendor.description}', '${vendor.website}', '${vendor.contact_person}', '${vendor.assignee}', '${vendor.status}', '${vendor.review_result}', '${vendor.reviewer}', '${vendor.review_date}', '${vendor.review_status}', '${vendor.risk_status}')`;
return `('${vendor.name}', '${vendor.type}', '${vendor.description}', '${vendor.website}', '${vendor.contact_person}', '${vendor.assignee}', '${vendor.status}', '${vendor.review_result}', '${vendor.review_status}', '${vendor.reviewer}', '${vendor.review_date}', '${vendor.risk_status}')`;
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions Servers/mocks/vendorRisks/vendorRisks.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const vendorRisks = [
},
{
id: 4,
vendor_id: 4,
vendor_id: 2,
risk_description: "Healthcare solution data handling does not meet compliance.",
impact_description: "Non-compliance could lead to legal issues and fines.",
project_id: 4,
Expand All @@ -57,7 +57,7 @@ export const vendorRisks = [
},
{
id: 5,
vendor_id: 5,
vendor_id: 1,
risk_description: "Aerospace components may not meet performance standards.",
impact_description: "Failure could lead to product malfunctions and safety concerns.",
project_id: 5,
Expand Down
Loading