11import type { Comment } from '@/pages/admin/ApplicationDetail/types/comments' ;
22
33export const fetchComments = async ( applicationId : number ) : Promise < Comment [ ] > => {
4- const response = await fetch (
5- import . meta. env . VITE_API_BASE_URL + `/applications/${ applicationId } /comments` ,
6- ) ;
4+ const url = `/api/applications/${ applicationId } /comments` ;
5+ const response = await fetch ( url ) ;
6+
7+ if ( ! response . ok ) throw new Error ( 'Failed to fetch comments' ) ;
78 return await response . json ( ) ;
89} ;
910
@@ -12,26 +13,26 @@ export const createComment = async (
1213 content : string ,
1314 rating : number ,
1415) : Promise < Comment > => {
15- const response = await fetch (
16- import . meta. env . VITE_API_BASE_URL + `/applications/${ applicationId } /comments` ,
17- {
18- method : 'POST' ,
19- headers : {
20- 'Content-Type' : 'application/json' ,
21- } ,
22- body : JSON . stringify ( { content, rating } ) ,
16+ const url = `/api/applications/${ applicationId } /comments` ;
17+ const response = await fetch ( url , {
18+ method : 'POST' ,
19+ headers : {
20+ 'Content-Type' : 'application/json' ,
2321 } ,
24- ) ;
22+ body : JSON . stringify ( { content, rating } ) ,
23+ } ) ;
24+
25+ if ( ! response . ok ) throw new Error ( 'Failed to create comment' ) ;
2526 return await response . json ( ) ;
2627} ;
2728
2829export const deleteComment = async ( applicationId : number , commentId : number ) : Promise < void > => {
29- await fetch (
30- import . meta . env . VITE_API_BASE_URL + `/applications/ ${ applicationId } /comments/ ${ commentId } ` ,
31- {
32- method : 'DELETE' ,
33- } ,
34- ) ;
30+ const url = `/api/applications/ ${ applicationId } /comments/ ${ commentId } ` ;
31+ const response = await fetch ( url , {
32+ method : 'DELETE' ,
33+ } ) ;
34+
35+ if ( ! response . ok ) throw new Error ( 'Failed to delete comment' ) ;
3536} ;
3637
3738export const updateComment = async (
@@ -40,15 +41,15 @@ export const updateComment = async (
4041 content : string ,
4142 rating : number ,
4243) : Promise < Comment > => {
43- const response = await fetch (
44- import . meta. env . VITE_API_BASE_URL + `/applications/${ applicationId } /comments/${ commentId } ` ,
45- {
46- method : 'PUT' ,
47- headers : {
48- 'Content-Type' : 'application/json' ,
49- } ,
50- body : JSON . stringify ( { content, rating } ) ,
44+ const url = `/api/applications/${ applicationId } /comments/${ commentId } ` ;
45+ const response = await fetch ( url , {
46+ method : 'PATCH' ,
47+ headers : {
48+ 'Content-Type' : 'application/json' ,
5149 } ,
52- ) ;
50+ body : JSON . stringify ( { content, rating } ) ,
51+ } ) ;
52+
53+ if ( ! response . ok ) throw new Error ( 'Failed to update comment' ) ;
5354 return await response . json ( ) ;
5455} ;
0 commit comments