-
Notifications
You must be signed in to change notification settings - Fork 15
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
052 Dec 5: Iterating the Assessment Tracker and Compliance Tracker #330
052 Dec 5: Iterating the Assessment Tracker and Compliance Tracker #330
Conversation
WalkthroughThe pull request introduces significant modifications to the assessment creation functionality within the application. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
Servers/controllers/assessment.ctrl.ts (2)
86-102
: Consider defining an interface fornewAssessment
for better readabilityThe in-line type definition for
newAssessment
is quite complex. Defining an interface or type alias would improve readability and maintainability.You can define an interface outside the function:
interface NewAssessment { projectId: number; title: string; subTopics: { id: number; title: string; questions: { id: number; question: string; hint: string; priorityLevel: string; answerType: string; inputType: string; isRequired: boolean; evidenceFileRequired: boolean; evidenceFile: string; }[]; }[]; }Then update the variable declaration:
-const newAssessment: { ... }[] = req.body; +const newAssessment: NewAssessment[] = req.body;
113-161
: Consider refactoring to eliminate the use of labels for better code clarityUsing the
mainLoop
label andbreak mainLoop
to control flow through nested asynchronous loops can reduce code readability. Labels are generally discouraged. Consider refactoring to avoid labels, possibly by using functions or additional condition checks.One possible approach is to refactor the nested loops into separate
async
functions and usereturn
statements to exit early on failure. For example:async function processAssessment(topicGroup: NewAssessment): Promise<boolean> { if (!topicGroup.projectId) { return false; } // ... rest of the code return true; } // In your main function let flag = true; for (const topicGroup of newAssessment) { flag = await processAssessment(topicGroup); if (!flag) { break; } }🧰 Tools
🪛 Biome (1.9.4)
[error] 117-117: Unnecessary label.
Safe fix: Remove the unnecessary label.
You can achieve the same result without the label.(lint/complexity/noUselessLabel)
[error] 129-129: Unnecessary label.
Safe fix: Remove the unnecessary label.
You can achieve the same result without the label.(lint/complexity/noUselessLabel)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
Servers/controllers/assessment.ctrl.ts
(3 hunks)Servers/routes/assessment.route.ts
(2 hunks)Servers/routes/question.route.ts
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
Servers/controllers/assessment.ctrl.ts
[error] 117-117: Unnecessary label.
Safe fix: Remove the unnecessary label.
You can achieve the same result without the label.
(lint/complexity/noUselessLabel)
[error] 129-129: Unnecessary label.
Safe fix: Remove the unnecessary label.
You can achieve the same result without the label.
(lint/complexity/noUselessLabel)
🔇 Additional comments (3)
Servers/controllers/assessment.ctrl.ts (2)
19-21
: Imports are appropriate and correctly added
The necessary imports for createNewQuestionQuery
, createNewTopicQuery
, createNewSubtopicQuery
, and RequestWithFile
have been correctly added.
80-80
: Update of request type to RequestWithFile
is appropriate
Changing the request type to RequestWithFile
accommodates file uploads in the createAssessment
function.
Servers/routes/question.route.ts (1)
19-19
: Removal of file upload middleware aligns with updated file handling
Since file uploads are now managed in the assessment route, removing the upload.any("files")
middleware from the question route is appropriate.
if (flag) { | ||
return res.status(201).json(STATUS_CODE[201]({})); | ||
} | ||
|
||
return res.status(503).json(STATUS_CODE[503]({})); | ||
return res.status(204).json(STATUS_CODE[204]({})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return an appropriate error status code instead of 204 when creation fails
Returning a 204 No Content status when the assessment creation fails may be misleading. A 400 (Bad Request) or 500 (Internal Server Error) status code would better indicate that the operation did not succeed.
Apply this diff to return a more suitable error status code:
-if (flag) {
- return res.status(201).json(STATUS_CODE[201]({}));
-}
-
-return res.status(204).json(STATUS_CODE[204]({}));
+if (flag) {
+ return res.status(201).json(STATUS_CODE[201]({}));
+} else {
+ return res.status(400).json(STATUS_CODE[400]({ message: "Assessment creation failed" }));
+}
📝 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.
if (flag) { | |
return res.status(201).json(STATUS_CODE[201]({})); | |
} | |
return res.status(503).json(STATUS_CODE[503]({})); | |
return res.status(204).json(STATUS_CODE[204]({})); | |
if (flag) { | |
return res.status(201).json(STATUS_CODE[201]({})); | |
} else { | |
return res.status(400).json(STATUS_CODE[400]({ message: "Assessment creation failed" })); | |
} |
@@ -16,7 +18,7 @@ router.get("/", /*authenticateJWT, */ getAllAssessments); | |||
router.get("/:id", /*authenticateJWT, */ getAssessmentById); | |||
|
|||
// POST, PUT, DELETE requests | |||
router.post("/", /*authenticateJWT, */ createAssessment); | |||
router.post("/", /*authenticateJWT, */ upload.any("files"), createAssessment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust multer middleware usage: upload.any()
does not accept field names
The upload.any()
method from multer does not accept any arguments. It accepts files from any field name. If you intend to accept files from a specific field, consider using upload.array('files')
or upload.single('file')
as appropriate.
Apply this diff to use the correct multer middleware method:
-router.post("/", /*authenticateJWT, */ upload.any("files"), createAssessment);
+router.post("/", /*authenticateJWT, */ upload.array("files"), createAssessment);
📝 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.
router.post("/", /*authenticateJWT, */ upload.any("files"), createAssessment); | |
router.post("/", /*authenticateJWT, */ upload.array("files"), createAssessment); |
@@ -1,5 +1,7 @@ | |||
import express from "express"; | |||
const router = express.Router(); | |||
const multer = require("multer"); | |||
const upload = multer({ Storage: multer.memoryStorage() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the option name 'Storage' to 'storage' in multer configuration
The configuration option for multer should be storage
(lowercase 's'), not Storage
. Using the incorrect option name will prevent multer from working properly.
Apply this diff to fix the typo:
-const upload = multer({ Storage: multer.memoryStorage() });
+const upload = multer({ storage: multer.memoryStorage() });
📝 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.
const upload = multer({ Storage: multer.memoryStorage() }); | |
const upload = multer({ storage: multer.memoryStorage() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @HarshP4585 for the nice code 🙏🏻, like always 🍻
However, there are a couple of things.
We both have done almost the same thing here, but the differences in our codes are:
1- You've only done the development in the server-side, but I have completed its implementation on both Client and Server side.
2 There were some fields that were missing, like the answer to questions itself 🤣
So, now I've added them.
- Now, You sir, have implemented the file uploaded related parts.
So, here's what we're going to do:
I'll merge my pr.
the you please, implemented the details that you have and I haven't.
Also please make sure everything in this potion works fine.
Regards,
Mo
POST /assessments
endpointPOST /controls
endpointAffected issues
Summary by CodeRabbit
New Features
Bug Fixes
Refactor