11import { Post , PostsApiResponse , NewPost } from "@entities/post/model/types"
2- import { createURLParams } from "@shared/lib"
2+ import { createURLParams , createApiUrl } from "@shared/lib"
33
44// Export hooks
55export * from "./queries"
@@ -16,7 +16,7 @@ export const fetchPosts = async (
1616 skip,
1717 ...( sortBy && sortBy !== "none" ? { sortBy, order : sortOrder } : { } ) ,
1818 } )
19- const response = await fetch ( `/api/ posts?${ query } `)
19+ const response = await fetch ( createApiUrl ( ` posts?${ query } `) )
2020 return response . json ( )
2121}
2222
@@ -33,7 +33,7 @@ export const searchPosts = async (
3333 skip,
3434 ...( sortBy && sortBy !== "none" ? { sortBy, order : sortOrder } : { } ) ,
3535 } )
36- const response = await fetch ( `/api/ posts/search?${ queryString } `)
36+ const response = await fetch ( createApiUrl ( ` posts/search?${ queryString } `) )
3737 return response . json ( )
3838}
3939
@@ -49,12 +49,12 @@ export const fetchPostsByTag = async (
4949 skip,
5050 ...( sortBy && sortBy !== "none" ? { sortBy, order : sortOrder } : { } ) ,
5151 } )
52- const response = await fetch ( `/api/ posts/tag/${ encodeURIComponent ( tag ) } ?${ queryString } `)
52+ const response = await fetch ( createApiUrl ( ` posts/tag/${ encodeURIComponent ( tag ) } ?${ queryString } `) )
5353 return response . json ( )
5454}
5555
5656export const addPost = async ( post : NewPost ) : Promise < Post > => {
57- const response = await fetch ( "/api/ posts/add", {
57+ const response = await fetch ( createApiUrl ( " posts/add") , {
5858 method : "POST" ,
5959 headers : { "Content-Type" : "application/json" } ,
6060 body : JSON . stringify ( post ) ,
@@ -63,7 +63,7 @@ export const addPost = async (post: NewPost): Promise<Post> => {
6363}
6464
6565export const updatePost = async ( id : number , post : Partial < Post > ) : Promise < Post > => {
66- const response = await fetch ( `/api/ posts/${ id } `, {
66+ const response = await fetch ( createApiUrl ( ` posts/${ id } `) , {
6767 method : "PUT" ,
6868 headers : { "Content-Type" : "application/json" } ,
6969 body : JSON . stringify ( post ) ,
@@ -72,12 +72,12 @@ export const updatePost = async (id: number, post: Partial<Post>): Promise<Post>
7272}
7373
7474export const deletePost = async ( id : number ) : Promise < void > => {
75- await fetch ( `/api/ posts/${ id } `, {
75+ await fetch ( createApiUrl ( ` posts/${ id } `) , {
7676 method : "DELETE" ,
7777 } )
7878}
7979
8080export const fetchTags = async ( ) => {
81- const response = await fetch ( "/api/ posts/tags")
81+ const response = await fetch ( createApiUrl ( " posts/tags") )
8282 return response . json ( )
8383}
0 commit comments