Skip to content

Commit 64620ec

Browse files
committed
fixed update endpoints, fixed testcases
1 parent c0ba710 commit 64620ec

27 files changed

+101
-89
lines changed

controller/accreditation.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ async function addAccreditation(req, res) {
1010
try {
1111
// eslint-disable-next-line max-len
1212
const accreditation = await addNewAccreditation(name, agencyName, dateofAccreditation, dateofExpiry);
13-
res.json({ res: `added accreditation ${accreditation.name}` });
13+
res.json({ res: `added accreditation ${accreditation.name}`, id:accreditation.id });
1414
} catch (error) {
1515
logger.error("Error while inserting", error);
1616
res.status(500);
1717
res.json({ err: "Error while inserting in DB" });
1818
}
1919
}
2020
async function deleteAccreditation(req, res) {
21-
const { accredationId } = req.params;
21+
const { id } = req.params;
2222
try {
23-
await deleteAccreditationById(accredationId);
23+
await deleteAccreditationById(id);
2424
res.json({ res: "Accreditation deleted successfully" });
2525
} catch (error) {
2626
logger.error("Error while deleting", error);
@@ -30,13 +30,14 @@ async function deleteAccreditation(req, res) {
3030
}
3131

3232
async function updateAccreditation(req, res) {
33+
const { id } = req.params;
3334
const {
34-
id, ...data
35+
...data
3536
} = req.body;
3637

3738
try {
3839
await updateAccreditationById(id, data);
39-
res.json({ res: "accreditation updated" });
40+
res.json({ res: `${id} accreditation updated` });
4041
} catch (error) {
4142
logger.error("Error while inserting", error);
4243
res.status(500);

controller/assignment.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function addAssignment(req, res) {
99
} = req.body;
1010
try {
1111
const newAssignment = await createAssignment(no, title, type, marks);
12-
res.json({ res: `added user ${newAssignment.id}` });
12+
res.json({ res: `added user ${newAssignment.id}`, id: newAssignment.id });
1313
} catch (error) {
1414
logger.error("Error while inserting", error);
1515
res.status(500);
@@ -18,8 +18,9 @@ async function addAssignment(req, res) {
1818
}
1919

2020
async function updateAssignment(req, res) {
21+
const { id } = req.params;
2122
const {
22-
id, ...data
23+
...data
2324
} = req.body;
2425
try {
2526
await updateAssignmentById(id, data);
@@ -38,11 +39,11 @@ async function getAssignment(req, res) {
3839
}
3940

4041
async function deleteAssignment(req, res) {
41-
const { assignmentId } = req.params;
42+
const { id } = req.params;
4243
try {
43-
await deleteAssignmentById(assignmentId);
44+
await deleteAssignmentById(id);
4445

45-
res.json({ res: `Deleted assignment with ID ${assignmentId}` });
46+
res.json({ res: `Deleted assignment with ID ${id}` });
4647
} catch (error) {
4748
logger.error("Error while deleting", error);
4849
res.status(500).json({ error: "Error while deleting from DB" });

controller/coursework.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function addCoursework(req, res) {
1717
const newCoursework = await createCoursework({
1818
student, type, course, task, objectID, activity, marks,
1919
});
20-
res.json({ res: `Added Coursework with ID ${newCoursework.id}` });
20+
res.json({ res: `Added Coursework with ID ${newCoursework.id}`, id: newCoursework.id});
2121
} catch (error) {
2222
logger.error("Error while inserting Coursework", error);
2323
res.status(500);
@@ -27,8 +27,9 @@ async function addCoursework(req, res) {
2727

2828
// Controller function to update a Coursework entity
2929
async function updateCoursework(req, res) {
30+
const { id } = req.params;
3031
const {
31-
id, ...data
32+
...data
3233
} = req.body;
3334
try {
3435
await updateCourseworkById(id, data);
@@ -49,10 +50,10 @@ async function getCoursework(req, res) {
4950

5051
// Controller function to delete a Coursework entity
5152
async function deleteCoursework(req, res) {
52-
const { courseworkId } = req.params;
53+
const { id } = req.params;
5354
try {
54-
await deleteCourseworkById(courseworkId);
55-
res.json({ res: `Deleted Coursework with ID ${courseworkId}` });
55+
await deleteCourseworkById(id);
56+
res.json({ res: `Deleted Coursework with ID ${id}` });
5657
} catch (error) {
5758
logger.error("Error while deleting Coursework", error);
5859
res.status(500).json({ error: "Error while deleting Coursework from DB" });

controller/department.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function addDepartment(req, res) {
2222
);
2323
res.json({
2424
res: `added Department successfully ${department.name}`,
25+
id: department.id,
2526
});
2627
} catch (error) {
2728
logger.error("Error while inserting", error);
@@ -58,8 +59,9 @@ async function showdepartments(req, res) {
5859
}
5960

6061
async function updatedDepartment(req, res) {
62+
const { id } = req.params;
6163
const {
62-
id, ...data
64+
...data
6365
} = req.body;
6466
try {
6567
await updateDepartmentbyid(id, data);

controller/infrastructure.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function addInfrastructure(req, res) {
99
} = req.body;
1010
try {
1111
const newInfrastructure = await createInfrastructure(name, type, wing, floor, capacity);
12-
res.json({ res: `added infrastructure ${newInfrastructure.id}` });
12+
res.json({ res: `added infrastructure ${newInfrastructure.id}`, id:newInfrastructure.id });
1313
} catch (error) {
1414
logger.error("Error while inserting", error);
1515
res.status(500);
@@ -18,8 +18,9 @@ async function addInfrastructure(req, res) {
1818
}
1919

2020
async function updateInfrastructure(req, res) {
21+
const { id } = req.params;
2122
const {
22-
id, ...data
23+
...data
2324
} = req.body;
2425
try {
2526
await updateInfrastructureById(id, data);
@@ -38,11 +39,11 @@ async function getInfrastructure(req, res) {
3839
}
3940

4041
async function deleteInfrastructure(req, res) {
41-
const { infrastructureId } = req.params;
42+
const { id } = req.params;
4243
try {
43-
await deleteInfrastructureById(infrastructureId);
44+
await deleteInfrastructureById(id);
4445

45-
res.json({ res: `Deleted infrastructure with ID ${infrastructureId}` });
46+
res.json({ res: `Deleted infrastructure with ID ${id}` });
4647
} catch (error) {
4748
logger.error("Error while deleting", error);
4849
res.status(500).json({ error: "Error while deleting from DB" });

controller/organization.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ async function addOrganization(req, res) {
99
} = req.body;
1010
try {
1111
const organization = await addNewOrganization(parent, startDate, name, accreditation);
12-
res.json({ res: `added organization${organization.name}` });
12+
res.json({ res: `added organization${organization.name}`, id:organization.id });
1313
} catch (error) {
1414
logger.error("Error while inserting", error);
1515
res.status(500);
1616
res.json({ err: "Error while inserting in DB" });
1717
}
1818
}
1919
async function deleteOrganization(req, res) {
20-
const { organizationId } = req.params;
20+
const { id } = req.params;
2121
try {
22-
await deleteOrganizationById(organizationId);
22+
await deleteOrganizationById(id);
2323
res.json({ res: "Organization deleted successfully" });
2424
} catch (error) {
2525
logger.error("Error while deleting", error);
@@ -29,8 +29,9 @@ async function deleteOrganization(req, res) {
2929
}
3030

3131
async function updateOrganization(req, res) {
32+
const { id } = req.params;
3233
const {
33-
id, ...data
34+
...data
3435
} = req.body;
3536

3637
try {

controller/practical.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function addPractical(req, res) {
1717
const newPractical = await createPractical({
1818
no, title, type, hours, cognitiveLevels,
1919
});
20-
res.json({ res: `Added Practical with ID ${newPractical.id}` });
20+
res.json({ res: `Added Practical with ID ${newPractical.id}`, id: newPractical.id });
2121
} catch (error) {
2222
logger.error("Error while inserting Practical", error);
2323
res.status(500);
@@ -27,8 +27,9 @@ async function addPractical(req, res) {
2727

2828
// Controller function to update a Practical entity
2929
async function updatePractical(req, res) {
30+
const { id } = req.params;
3031
const {
31-
id, ...data
32+
...data
3233
} = req.body;
3334
try {
3435
await updatePracticalById(id, data);
@@ -49,10 +50,10 @@ async function getPractical(req, res) {
4950

5051
// Controller function to delete a Practical entity
5152
async function deletePractical(req, res) {
52-
const { practicalId } = req.params;
53+
const { id } = req.params;
5354
try {
54-
await deletePracticalById(practicalId);
55-
res.json({ res: `Deleted Practical with ID ${practicalId}` });
55+
await deletePracticalById(id);
56+
res.json({ res: `Deleted Practical with ID ${id}` });
5657
} catch (error) {
5758
logger.error("Error while deleting Practical", error);
5859
res.status(500).json({ error: "Error while deleting Practical from DB" });

controller/student.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function addStudent(req, res) {
1717
rollNo,
1818
coursesOpted,
1919
);
20-
res.json({ res: `added user ${newStudent.id}` });
20+
res.json({ res: `added user ${newStudent.id}`, id: newStudent.id });
2121
} catch (error) {
2222
logger.error("Error while inserting", error);
2323
res.status(500);
@@ -26,8 +26,9 @@ async function addStudent(req, res) {
2626
}
2727

2828
async function updateStudent(req, res) {
29+
const { id } = req.params;
2930
const {
30-
id, ...data
31+
...data
3132
} = req.body;
3233
try {
3334
await updateStudentById(id, data);
@@ -46,11 +47,11 @@ async function getStudent(req, res) {
4647
}
4748

4849
async function deleteStudent(req, res) {
49-
const { StudentId } = req.params;
50+
const { id } = req.params;
5051
try {
51-
await deleteStudentById(StudentId);
52+
await deleteStudentById(id);
5253

53-
res.json({ res: `Deleted Student with ID ${StudentId}` });
54+
res.json({ res: `Deleted Student with ID ${id}` });
5455
} catch (error) {
5556
logger.error("Error while deleting", error);
5657
res.status(500).json({ error: "Error while deleting from DB" });

controller/timetable.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function addTimetable(req, res) {
2727
teabreakStartTime,
2828
teabreakDuration,
2929
);
30-
res.json({ res: `added timetable for: ${newTimetable.startDate} to ${newTimetable.endDate}` });
30+
res.json({ res: `added timetable for: ${newTimetable.startDate} to ${newTimetable.endDate}`, id: newTimetable.id });
3131
} catch (error) {
3232
logger.error("Error while inserting", error);
3333
res.status(500);
@@ -36,8 +36,9 @@ async function addTimetable(req, res) {
3636
}
3737

3838
async function updateTimetable(req, res) {
39+
const { id } = req.params;
3940
const {
40-
id, ...data
41+
...data
4142
} = req.body;
4243
try {
4344
await updateTimetableById(id, data);
@@ -56,10 +57,10 @@ async function getTimetable(req, res) {
5657
}
5758

5859
async function deleteTimetable(req, res) {
59-
const { timetableId } = req.params;
60+
const { id } = req.params;
6061
try {
61-
await deleteTimetableById(timetableId);
62-
res.json({ res: `Deleted timetable with ID ${timetableId}` });
62+
await deleteTimetableById(id);
63+
res.json({ res: `Deleted timetable with ID ${id}` });
6364
} catch (error) {
6465
logger.error("Error while deleting", error);
6566
res.status(500).json({ error: "Error while deleting from DB" });

controller/tutorial.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ async function addTutorial(req, res) {
1010
try {
1111
// eslint-disable-next-line max-len
1212
const tutorial = await addNewTutorial(no, title, hours, cognitiveLevel);
13-
res.json({ res: `added tutorial ${tutorial.name}` });
13+
res.json({ res: `added tutorial ${tutorial.name}`, id: tutorial.id });
1414
} catch (error) {
1515
logger.error("Error while inserting", error);
1616
res.status(500);
1717
res.json({ err: "Error while inserting in DB" });
1818
}
1919
}
2020
async function deleteTutorial(req, res) {
21-
const { tutorialId } = req.params;
21+
const { id } = req.params;
2222
try {
23-
await deleteTutorialById(tutorialId);
23+
await deleteTutorialById(id);
2424
res.json({ res: "Tutorial deleted successfully" });
2525
} catch (error) {
2626
logger.error("Error while deleting", error);
@@ -30,8 +30,9 @@ async function deleteTutorial(req, res) {
3030
}
3131

3232
async function updateTutorial(req, res) {
33+
const { id } = req.params;
3334
const {
34-
id, ...data
35+
...data
3536
} = req.body;
3637

3738
try {

0 commit comments

Comments
 (0)