Skip to content

Commit 5a11a4e

Browse files
committed
fix semesters not sorting correctly bug
1 parent 3cd6213 commit 5a11a4e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/server/trpc/router/plan.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ import { TRPCError } from '@trpc/server';
22
import { z } from 'zod';
33

44
import { Semester as PlanSemester } from '@/components/planner/types';
5-
import {
6-
createNewYear,
7-
createSemesterCodeRange,
8-
isSemesterEarlier,
9-
isSemesterLater,
10-
} from '@/utils/utilFunctions';
5+
import { createNewYear, createSemesterCodeRange } from '@/utils/utilFunctions';
116

127
import { protectedProcedure, router } from '../trpc';
138
import { Prisma, SemesterCode, Semester } from '@prisma/client';
149
import { ObjectId } from 'bson';
10+
import { isEarlierSemester } from '@/utils/plannerUtils';
1511

1612
export const planRouter = router({
1713
// Protected route: route uses session user id to find user plans
@@ -53,6 +49,13 @@ export const planRouter = router({
5349
},
5450
});
5551

52+
// Make sure semesters are in right orer
53+
if (planData && planData.semesters) {
54+
planData.semesters = planData.semesters.sort((a, b) =>
55+
isEarlierSemester(a.code, b.code) ? -1 : 1,
56+
);
57+
}
58+
5659
if (!planData) {
5760
throw new TRPCError({
5861
code: 'NOT_FOUND',

src/server/trpc/router/user.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ export const userRouter = router({
367367
},
368368
},
369369
},
370+
orderBy: {
371+
semester: 'asc',
372+
},
370373
},
371374
},
372375
});

0 commit comments

Comments
 (0)