generated from agiledev-students-fall2023/generic-project-repository
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from agiledev-students-fall2023/sprint/4/spik…
…e/337/lint-backend Sprint/4/spike/337/lint backend
- Loading branch information
Showing
15 changed files
with
174 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
import Issue from '../../models/issueModel.js'; | ||
/* eslint-disable no-unused-vars */ | ||
import Issue from "../../models/issueModel.js"; | ||
|
||
export async function createIssueHandler(req, res) { | ||
const { | ||
dateCreated, | ||
currentStatus, | ||
currentPriority | ||
} = req.body; | ||
const { dateCreated, currentStatus, currentPriority } = req.body; | ||
|
||
const currentDate = new Date(); | ||
const day = String(currentDate.getDate()).padStart(2, '0'); | ||
const month = String(currentDate.getMonth() + 1).padStart(2, '0'); | ||
const year = currentDate.getFullYear(); | ||
const formattedDate = `${day}/${month}/${year}`; | ||
const issueDateCreated = dateCreated || formattedDate; | ||
const issueTimeCreated = new Date().toLocaleTimeString('en-US', { | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
hour12: false, | ||
timeZone: 'Asia/Dubai' | ||
}); | ||
const attachments = req.files.map(file => file.filename); | ||
const lastIssue = await Issue.findOne().sort({ index: -1 }); | ||
const newIndex = lastIssue ? lastIssue.index + 1 : 1; | ||
const currentDate = new Date(); | ||
const day = String(currentDate.getDate()).padStart(2, "0"); | ||
const month = String(currentDate.getMonth() + 1).padStart(2, "0"); | ||
const year = currentDate.getFullYear(); | ||
const formattedDate = `${day}/${month}/${year}`; | ||
const issueDateCreated = dateCreated || formattedDate; | ||
const issueTimeCreated = new Date().toLocaleTimeString("en-US", { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
timeZone: "Asia/Dubai" | ||
}); | ||
const attachments = req.files.map((file) => file.filename); | ||
const lastIssue = await Issue.findOne().sort({ index: -1 }); | ||
const newIndex = lastIssue ? lastIssue.index + 1 : 1; | ||
|
||
const newIssue = new Issue ({ | ||
index: newIndex, | ||
studentNetID: req.params.studentNetID, | ||
studentName: req.body.studentName, | ||
title: req.body.issueTitle, | ||
description: req.body.issueDesc, | ||
attachments: attachments, | ||
departments: req.body.deptTagged.includes(',') ? req.body.deptTagged.split(',') : [req.body.deptTagged], | ||
comments: [], | ||
dateCreated: issueDateCreated, | ||
timeCreated: issueTimeCreated, | ||
currentStatus:'Open', | ||
currentPriority: 'New', | ||
isProposed: false, | ||
isProposedDate: '', | ||
}); | ||
const newIssue = new Issue({ | ||
index: newIndex, | ||
studentNetID: req.params.studentNetID, | ||
studentName: req.body.studentName, | ||
title: req.body.issueTitle, | ||
description: req.body.issueDesc, | ||
attachments, | ||
departments: req.body.deptTagged.includes(",") | ||
? req.body.deptTagged.split(",") | ||
: [req.body.deptTagged], | ||
comments: [], | ||
dateCreated: issueDateCreated, | ||
timeCreated: issueTimeCreated, | ||
currentStatus: "Open", | ||
currentPriority: "New", | ||
isProposed: false, | ||
isProposedDate: "" | ||
}); | ||
|
||
try { | ||
await newIssue.save(); | ||
res.status(200).send('Issue created successfully'); | ||
} catch (error) { | ||
console.error('Error creating issue:', error.message); | ||
res.status(500).send("An error occurred while saving the data."); | ||
} | ||
try { | ||
await newIssue.save(); | ||
res.status(200).send("Issue created successfully"); | ||
} catch (error) { | ||
console.error("Error creating issue:", error.message); | ||
res.status(500).send("An error occurred while saving the data."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,51 @@ | ||
import Issue from '../../models/issueModel.js'; | ||
import Issue from "../../models/issueModel.js"; | ||
// The function updates the issue related to this student | ||
export async function studentIssueUpdateHandler(req, res) { | ||
const { paramName } = req.params; // Get the issue index from request params | ||
const { studentNetID } = req.params; // Get the studentNetID from request params | ||
const newcomment = req.body.comments; | ||
const currentStatus = req.body.currentStatus; | ||
const currentPriority = req.body.currentPriority; | ||
const isProposed = req.body.isProposed; | ||
const { paramName } = req.params; // Get the issue index from request params | ||
const { studentNetID } = req.params; // Get the studentNetID from request params | ||
const newcomment = req.body.comments; | ||
const currentStatus = req.body.currentStatus; | ||
const currentPriority = req.body.currentPriority; | ||
const isProposed = req.body.isProposed; | ||
try { | ||
const specificIssue = await Issue.findOne({ studentNetID: studentNetID, index: paramName }); | ||
const specificIssue = await Issue.findOne({ | ||
studentNetID, | ||
index: paramName | ||
}); | ||
|
||
if (newcomment !== undefined) { | ||
specificIssue.comments.unshift(newcomment); | ||
specificIssue.comments.unshift(newcomment); | ||
} | ||
if (currentStatus !== undefined) { | ||
specificIssue.currentStatus = currentStatus; | ||
specificIssue.currentStatus = currentStatus; | ||
} | ||
if (currentPriority !== undefined) { | ||
specificIssue.currentPriority = currentPriority; | ||
} | ||
if (isProposed !== undefined) { | ||
specificIssue.isProposed = isProposed; | ||
} | ||
if (specificIssue.currentStatus === 'Resolved') { | ||
if (specificIssue.currentStatus === "Resolved") { | ||
specificIssue.currentPriority = ""; | ||
} | ||
if (req.files !== undefined) { | ||
const newfilesattachments = req.files.map(file => file.filename); | ||
const newfilesattachments = req.files.map((file) => file.filename); | ||
if (specificIssue.attachments[0] == null) { | ||
specificIssue.attachments = newfilesattachments; | ||
} else { | ||
newfilesattachments.forEach(element => { | ||
newfilesattachments.forEach((element) => { | ||
specificIssue.attachments.push(element); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
const updatedIssue = await specificIssue.save(); | ||
|
||
// Send a response back to the client indicating success | ||
res.json({ message: 'Issue updated successfully', updatedIssue }); | ||
res.json({ message: "Issue updated successfully", updatedIssue }); | ||
} catch (error) { | ||
// Log the error and send an appropriate response | ||
console.error('Error updating data:', error.message); | ||
res.status(500).send('An error occurred while updating the data.'); | ||
console.error("Error updating data:", error.message); | ||
res.status(500).send("An error occurred while updating the data."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.