Skip to content

Commit 2aa839b

Browse files
committed
Fixes + Integrate Creating Restrictions
1 parent 7fb2256 commit 2aa839b

File tree

6 files changed

+383
-346
lines changed

6 files changed

+383
-346
lines changed

course-matrix/backend/src/controllers/coursesController.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ export default {
114114
try {
115115
const { course_ids, semester } = req.query;
116116

117-
if (!course_ids || !semester) {
118-
return res.status(400).send({
119-
error: "Missing required parameters: course_ids, semester",
120-
});
117+
if (!semester) {
118+
return res.status(400).send({ error: "Semester is required" });
119+
}
120+
121+
if (!course_ids) {
122+
return res.status(200).send({ totalNumberOfCourseSections: 0 });
121123
}
122124

123125
const course_ids_array = (course_ids as string).split(",");
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { apiSlice } from "./baseApiSlice";
2+
import { TIMETABLES_URL } from "./config";
3+
4+
// Endpoints for /api/timetables/restrictions
5+
export const restrictionsApiSlice = apiSlice.injectEndpoints({
6+
endpoints: (builder) => ({
7+
getRestrictions: builder.query({
8+
query: (id) => ({
9+
url: `${TIMETABLES_URL}/restrictions/${id}`,
10+
method: "GET",
11+
headers: {
12+
"Content-Type": "application/json",
13+
Accept: "application/json, text/plain, */*",
14+
},
15+
providesTags: ["Restrictions"],
16+
credentials: "include",
17+
}),
18+
}),
19+
createRestriction: builder.mutation({
20+
query: (data) => ({
21+
url: `${TIMETABLES_URL}/restrictions`,
22+
method: "POST",
23+
headers: {
24+
"Content-Type": "application/json",
25+
Accept: "application/json, text/plain, */*",
26+
},
27+
providesTags: ["Restrictions"],
28+
body: data,
29+
credentials: "include",
30+
}),
31+
}),
32+
deleteRestriction: builder.mutation({
33+
query: (id) => ({
34+
url: `${TIMETABLES_URL}/restrictions/${id}`,
35+
method: "DELETE",
36+
headers: {
37+
"Content-Type": "application/json",
38+
Accept: "application/json, text/plain, */*",
39+
},
40+
providesTags: ["Restrictions"],
41+
credentials: "include",
42+
}),
43+
}),
44+
}),
45+
});
46+
47+
export const { useGetRestrictionsQuery, useCreateRestrictionMutation, useDeleteRestrictionMutation } =
48+
restrictionsApiSlice;

0 commit comments

Comments
 (0)