Skip to content

Commit 02c4c83

Browse files
authored
Merge pull request #127 from Coding-Club-IITG/prajit
fix bugs related to sorting the years
2 parents 4290aa4 + 6030963 commit 02c4c83

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

client/src/screens/browse/components/year-info/index.jsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ const YearInfo = ({
3131
(c) => c.code.toLowerCase() === courseCode?.toLowerCase()
3232
);
3333

34-
const sortYear = (a, b) => {
35-
if (a?.name > b?.name) return 1;
36-
else if(a?.name < b?.name) return -1;
37-
else return 1;
38-
}
39-
40-
if(course?.length > 1) course.sort(sortYear);
41-
4234
const handleAddYear = () => {
4335
setNewYearName("");
4436
setShowConfirm(true);

server/modules/course/course.controller.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export const getCourse = async (req, res, next) => {
6464
if (!course) {
6565
course = await createCourse(code);
6666
}
67+
68+
//function to sort the years in descending order for displaying in frontend
69+
const sortYear = (a, b) => {
70+
if (a?.name > b?.name) return 1;
71+
else if(a?.name < b?.name) return -1;
72+
else return 1;
73+
}
74+
75+
if(course?.children.length > 1) course.children.sort(sortYear);
6776
return res.json({ found: true, ...course["_doc"] });
6877
};
6978

0 commit comments

Comments
 (0)