Skip to content

Commit cbdbd1f

Browse files
Austin-Xgithub-actions[bot]
authored andcommitted
Auto-formatted the code using Prettier
1 parent 2da4ff0 commit cbdbd1f

File tree

14 files changed

+428
-307
lines changed

14 files changed

+428
-307
lines changed

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -153,51 +153,49 @@ export default {
153153
* Get all restrictions from a shared timetable id
154154
* @route GET /api/shared/restrictions/:calendar_id
155155
*/
156-
getSharedRestrictions: asyncHandler(
157-
async (req: Request, res: Response) => {
158-
try {
159-
const { user_id, calendar_id } = req.query;
160-
161-
if (!user_id || !calendar_id) {
162-
return res.status(400).json({
163-
error: "User ID and Calendar ID are required",
164-
});
165-
}
156+
getSharedRestrictions: asyncHandler(async (req: Request, res: Response) => {
157+
try {
158+
const { user_id, calendar_id } = req.query;
166159

167-
//Retrieve users allowed to access the timetable
168-
const { data: timetableData, error: timetableError } = await supabase
169-
.schema("timetable")
170-
.from("timetables")
171-
.select("*")
172-
.eq("id", calendar_id)
173-
.eq("user_id", user_id)
174-
.maybeSingle();
160+
if (!user_id || !calendar_id) {
161+
return res.status(400).json({
162+
error: "User ID and Calendar ID are required",
163+
});
164+
}
175165

176-
if (timetableError)
177-
return res.status(400).json({ error: timetableError.message });
166+
//Retrieve users allowed to access the timetable
167+
const { data: timetableData, error: timetableError } = await supabase
168+
.schema("timetable")
169+
.from("timetables")
170+
.select("*")
171+
.eq("id", calendar_id)
172+
.eq("user_id", user_id)
173+
.maybeSingle();
178174

179-
//Validate timetable validity:
180-
if (!timetableData || timetableData.length === 0) {
181-
return res.status(404).json({ error: "Calendar id not found" });
182-
}
175+
if (timetableError)
176+
return res.status(400).json({ error: timetableError.message });
183177

184-
const { data: restrictionData, error: restrictionError } = await supabase
185-
.schema("timetable")
186-
.from("restriction")
187-
.select()
188-
.eq("user_id", user_id)
189-
.eq("calendar_id", calendar_id);
178+
//Validate timetable validity:
179+
if (!timetableData || timetableData.length === 0) {
180+
return res.status(404).json({ error: "Calendar id not found" });
181+
}
190182

191-
if (restrictionError) {
192-
return res.status(400).json({ error: restrictionError.message });
193-
}
183+
const { data: restrictionData, error: restrictionError } = await supabase
184+
.schema("timetable")
185+
.from("restriction")
186+
.select()
187+
.eq("user_id", user_id)
188+
.eq("calendar_id", calendar_id);
194189

195-
return res.status(200).json(restrictionData);
196-
} catch (error) {
197-
return res.status(500).send({ error });
190+
if (restrictionError) {
191+
return res.status(400).json({ error: restrictionError.message });
198192
}
193+
194+
return res.status(200).json(restrictionData);
195+
} catch (error) {
196+
return res.status(500).send({ error });
199197
}
200-
),
198+
}),
201199

202200
/**
203201
* Delete all shared record for a timetable as the timetable's owner

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export const updateUsername = asyncHandler(
298298
/**
299299
* @route GET
300300
* @description Gets a user's username from their user ID
301-
*
301+
*
302302
* This endpoint:
303303
* - Takes 1 field, the user's id
304304
* - Calls supabase's getUsers() function
@@ -312,10 +312,14 @@ export const usernameFromUserId = asyncHandler(
312312
return res.status(400).json({ error: "User ID is required" });
313313
}
314314

315-
const { data: userData, error } = await supabase.auth.admin.getUserById(user_id as string);
315+
const { data: userData, error } = await supabase.auth.admin.getUserById(
316+
user_id as string,
317+
);
316318

317319
if (error) {
318-
return res.status(400).json({ error: "Unable to get username from email" });
320+
return res
321+
.status(400)
322+
.json({ error: "Unable to get username from email" });
319323
} else {
320324
const username = userData?.user?.user_metadata?.username;
321325
return res.status(200).json(username);

course-matrix/backend/src/routes/authRouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
resetPassword,
1111
accountDelete,
1212
updateUsername,
13-
usernameFromUserId
13+
usernameFromUserId,
1414
} from "../controllers/userController";
1515
import { authHandler } from "../middleware/authHandler";
1616

@@ -74,4 +74,4 @@ authRouter.post("/updateUsername", authHandler, updateUsername);
7474
* Route to get the username from the user id
7575
* @route GET /username-from-user-id
7676
*/
77-
authRouter.get("/username-from-user-id", authHandler, usernameFromUserId);
77+
authRouter.get("/username-from-user-id", authHandler, usernameFromUserId);

course-matrix/backend/src/routes/timetableRouter.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ timetableRouter.get(
7070
* @route GET /api/timetables/events/shared
7171
* @middleware authHandler - Middleware to check if the user is authenticated.
7272
*/
73-
timetableRouter.get("/events/shared/:user_id/:calendar_id", authHandler, eventController.getSharedEvents);
73+
timetableRouter.get(
74+
"/events/shared/:user_id/:calendar_id",
75+
authHandler,
76+
eventController.getSharedEvents,
77+
);
7478

7579
/**
7680
* Route to update an event
@@ -166,7 +170,11 @@ timetableRouter.get("/shared/me", authHandler, sharesController.getShare);
166170
* @route GET /api/timetables/shared/restrictions
167171
* @middleware authHandler - Middleware to check if the user is authenticated
168172
*/
169-
timetableRouter.get("/shared/restrictions", authHandler, sharesController.getSharedRestrictions);
173+
timetableRouter.get(
174+
"/shared/restrictions",
175+
authHandler,
176+
sharesController.getSharedRestrictions,
177+
);
170178

171179
/**
172180
* Route to delete all shared entries for a timetable as timetable's owner
@@ -184,8 +192,4 @@ timetableRouter.delete(
184192
* @route DELETE /api/timetables/shared/me/:calendar_id
185193
* @middleware authHandler - Middleware to check if the user is authenticated
186194
*/
187-
timetableRouter.delete(
188-
"/shared/me",
189-
authHandler,
190-
sharesController.deleteShare,
191-
);
195+
timetableRouter.delete("/shared/me", authHandler, sharesController.deleteShare);

course-matrix/frontend/src/api/eventsApiSlice.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export const eventsApiSlice = apiSlice.injectEndpoints({
3030
}),
3131
keepUnusedDataFor: 0,
3232
}),
33-
getSharedEvents: builder.query<unknown, { user_id: string; calendar_id: number }>({
33+
getSharedEvents: builder.query<
34+
unknown,
35+
{ user_id: string; calendar_id: number }
36+
>({
3437
query: (data) => ({
3538
url: `${EVENTS_URL}/shared/${data.user_id}/${data.calendar_id}`,
3639
method: "GET",

course-matrix/frontend/src/api/sharedApiSlice.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export const sharedApiSlice = apiSlice.injectEndpoints({
4343
}),
4444
keepUnusedDataFor: 0,
4545
}),
46-
getSharedRestrictions: builder.query<unknown, { user_id: string; calendar_id: number }>({
46+
getSharedRestrictions: builder.query<
47+
unknown,
48+
{ user_id: string; calendar_id: number }
49+
>({
4750
query: (data) => ({
4851
url: `${SHARED_URL}/restrictions`,
4952
method: "GET",
@@ -71,17 +74,17 @@ export const sharedApiSlice = apiSlice.injectEndpoints({
7174
invalidatesTags: ["Timetable"],
7275
}),
7376
deleteSharedTimetablesWithOthers: builder.mutation({
74-
query: (data) => ({
75-
url: `${SHARED_URL}/owner/${data.id}`,
76-
method: "DELETE",
77-
headers: {
78-
"Content-Type": "application/json",
79-
Accept: "application/json, text/plain, */*",
80-
},
81-
body: data,
82-
credentials: "include",
83-
}),
84-
invalidatesTags: ["Timetable"],
77+
query: (data) => ({
78+
url: `${SHARED_URL}/owner/${data.id}`,
79+
method: "DELETE",
80+
headers: {
81+
"Content-Type": "application/json",
82+
Accept: "application/json, text/plain, */*",
83+
},
84+
body: data,
85+
credentials: "include",
86+
}),
87+
invalidatesTags: ["Timetable"],
8588
}),
8689
}),
8790
});
@@ -93,4 +96,4 @@ export const {
9396
useGetSharedRestrictionsQuery,
9497
useDeleteSharedTimetablesWithMeMutation,
9598
useDeleteSharedTimetablesWithOthersMutation,
96-
} = sharedApiSlice;
99+
} = sharedApiSlice;

0 commit comments

Comments
 (0)