@@ -21,7 +21,7 @@ export const api = {
2121 } ,
2222
2323 getById : async ( id : string ) : Promise < IClassroom > => {
24- const res = await fetch ( `${ API_URL } /classrooms/${ id } ` , {
24+ const res = await fetch ( `${ API_URL } /classrooms/${ encodeURIComponent ( id ) } ` , {
2525 headers : {
2626 ...getAuthHeaders ( )
2727 }
@@ -57,7 +57,7 @@ export const api = {
5757 thumbnailId : number ;
5858 }
5959 ) : Promise < { id : string } > => {
60- const res = await fetch ( `${ API_URL } /classrooms/${ id } ` , {
60+ const res = await fetch ( `${ API_URL } /classrooms/${ encodeURIComponent ( id ) } ` , {
6161 method : 'PUT' ,
6262 headers : {
6363 'Content-Type' : 'application/json' ,
@@ -71,7 +71,8 @@ export const api = {
7171 } ,
7272
7373 join : async ( code : string ) : Promise < IClassroom > => {
74- const res = await fetch ( `${ API_URL } /classrooms/join/${ code } ` , {
74+ const res = await fetch ( `${ API_URL } /classrooms/join/${ encodeURIComponent ( code ) } ` , {
75+ method : 'POST' ,
7576 headers : {
7677 ...getAuthHeaders ( )
7778 }
@@ -84,7 +85,7 @@ export const api = {
8485
8586 activities : {
8687 getByClassroom : async ( classroomId : string ) : Promise < IActivity [ ] > => {
87- const res = await fetch ( `${ API_URL } /classrooms/${ classroomId } /activities` , {
88+ const res = await fetch ( `${ API_URL } /classrooms/${ encodeURIComponent ( classroomId ) } /activities` , {
8889 headers : {
8990 ...getAuthHeaders ( )
9091 }
@@ -95,11 +96,14 @@ export const api = {
9596 } ,
9697
9798 getById : async ( classroomId : string , activityId : string ) : Promise < IActivity > => {
98- const res = await fetch ( `${ API_URL } /classrooms/${ classroomId } /activities/${ activityId } ` , {
99- headers : {
100- ...getAuthHeaders ( )
99+ const res = await fetch (
100+ `${ API_URL } /classrooms/${ encodeURIComponent ( classroomId ) } /activities/${ encodeURIComponent ( activityId ) } ` ,
101+ {
102+ headers : {
103+ ...getAuthHeaders ( )
104+ }
101105 }
102- } ) ;
106+ ) ;
103107
104108 if ( ! res . ok ) throw new Error ( 'Failed to fetch activity' ) ;
105109 return res . json ( ) ;
@@ -122,7 +126,7 @@ export const api = {
122126 } ;
123127 }
124128 ) : Promise < { id : string } > => {
125- const res = await fetch ( `${ API_URL } /classrooms/${ classroomId } /activities` , {
129+ const res = await fetch ( `${ API_URL } /classrooms/${ encodeURIComponent ( classroomId ) } /activities` , {
126130 method : 'POST' ,
127131 headers : {
128132 'Content-Type' : 'application/json' ,
@@ -153,14 +157,17 @@ export const api = {
153157 } ;
154158 }
155159 ) : Promise < IActivity > => {
156- const res = await fetch ( `${ API_URL } /classrooms/${ classroomId } /activities/${ activityId } ` , {
157- method : 'PUT' ,
158- headers : {
159- 'Content-Type' : 'application/json' ,
160- ...getAuthHeaders ( )
161- } ,
162- body : JSON . stringify ( data )
163- } ) ;
160+ const res = await fetch (
161+ `${ API_URL } /classrooms/${ encodeURIComponent ( classroomId ) } /activities/${ encodeURIComponent ( activityId ) } ` ,
162+ {
163+ method : 'PUT' ,
164+ headers : {
165+ 'Content-Type' : 'application/json' ,
166+ ...getAuthHeaders ( )
167+ } ,
168+ body : JSON . stringify ( data )
169+ }
170+ ) ;
164171
165172 if ( ! res . ok ) throw new Error ( 'Failed to update activity' ) ;
166173 return res . json ( ) ;
0 commit comments