@@ -2,7 +2,10 @@ import { supabase } from "../db/setupDb";
22import { Request } from "express" ;
33
44// Add all possible function names here
5- export type FunctionNames = "getTimetables" | "updateTimetable" | "deleteTimetable" ;
5+ export type FunctionNames =
6+ | "getTimetables"
7+ | "updateTimetable"
8+ | "deleteTimetable" ;
69
710type AvailableFunctions = {
811 [ K in FunctionNames ] : ( args : any , req : Request ) => Promise < any > ;
@@ -43,7 +46,7 @@ export const availableFunctions: AvailableFunctions = {
4346 } ,
4447 updateTimetable : async ( args : any , req : Request ) => {
4548 try {
46- const { id, timetable_title, semester } = args ;
49+ const { id, timetable_title, semester } = args ;
4750
4851 if ( ! timetable_title && ! semester ) {
4952 return {
@@ -69,16 +72,19 @@ export const availableFunctions: AvailableFunctions = {
6972 const timetable_user_id = timetableUserData ?. user_id ;
7073
7174 if ( timetableUserError )
72- return { status : 400 , error : timetableUserError . message } ;
75+ return { status : 400 , error : timetableUserError . message } ;
7376
7477 //Validate timetable validity:
7578 if ( ! timetableUserData || timetableUserData . length === 0 ) {
76- return { status : 404 , error : "Calendar id not found" } ;
79+ return { status : 404 , error : "Calendar id not found" } ;
7780 }
7881
7982 //Validate user access
8083 if ( user_id !== timetable_user_id ) {
81- return { status : 401 , error : "Unauthorized access to timetable events" } ;
84+ return {
85+ status : 401 ,
86+ error : "Unauthorized access to timetable events" ,
87+ } ;
8288 }
8389
8490 let updateData : any = { } ;
@@ -97,8 +103,7 @@ export const availableFunctions: AvailableFunctions = {
97103 const { data : timetableData , error : timetableError } =
98104 await updateTimetableQuery ;
99105
100- if ( timetableError )
101- return { status : 400 , error : timetableError . message } ;
106+ if ( timetableError ) return { status : 400 , error : timetableError . message } ;
102107
103108 // If no records were updated due to non-existence timetable or it doesn't belong to the user.
104109 if ( ! timetableData || timetableData . length === 0 ) {
@@ -109,7 +114,7 @@ export const availableFunctions: AvailableFunctions = {
109114 }
110115 return { status : 200 , data : timetableData } ;
111116 } catch ( error ) {
112- return { status : 500 , error : error } ;
117+ return { status : 500 , error : error } ;
113118 }
114119 } ,
115120 deleteTimetable : async ( args : any , req : Request ) => {
@@ -135,12 +140,15 @@ export const availableFunctions: AvailableFunctions = {
135140
136141 //Validate timetable validity:
137142 if ( ! timetableUserData || timetableUserData . length === 0 ) {
138- return { status : 404 , error : "Calendar id not found" } ;
143+ return { status : 404 , error : "Calendar id not found" } ;
139144 }
140145
141146 //Validate user access
142147 if ( user_id !== timetable_user_id ) {
143- return { status : 401 , error : "Unauthorized access to timetable events" } ;
148+ return {
149+ status : 401 ,
150+ error : "Unauthorized access to timetable events" ,
151+ } ;
144152 }
145153
146154 // Delete only if the timetable belongs to the authenticated user
@@ -153,12 +161,11 @@ export const availableFunctions: AvailableFunctions = {
153161
154162 const { error : timetableError } = await deleteTimetableQuery ;
155163
156- if ( timetableError )
157- return { status : 400 , error : timetableError . message } ;
164+ if ( timetableError ) return { status : 400 , error : timetableError . message } ;
158165
159- return { status : 200 , data : "Timetable successfully deleted" } ;
166+ return { status : 200 , data : "Timetable successfully deleted" } ;
160167 } catch ( error ) {
161168 return { status : 500 , error : error } ;
162169 }
163- }
170+ } ,
164171} ;
0 commit comments