feat(api): add post creation client
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ export { getGameById, listGames } from "./games"
|
||||
export { listNotifications, markNotificationAsRead } from "./notifications"
|
||||
export { getOrderById, listOrders, listOrdersByConsumer } from "./orders"
|
||||
export { getPlayerById, listPlayers, listPlayersByShop } from "./players"
|
||||
export { getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts"
|
||||
export { createPost, getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts"
|
||||
export { listReviews, listReviewsByOrder, listReviewsByTargetUser } from "./reviews"
|
||||
export {
|
||||
createPlayerService,
|
||||
|
||||
@@ -17,6 +17,14 @@ type ListOptions = {
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export type CreatePostInput = {
|
||||
title: string
|
||||
content: string
|
||||
images: string[]
|
||||
tags: string[]
|
||||
linkedOrderId?: string
|
||||
}
|
||||
|
||||
function withOffsetLimit(path: string, options?: ListOptions): string {
|
||||
const offset = options?.offset ?? 0
|
||||
const limit = options?.limit ?? 100
|
||||
@@ -51,6 +59,20 @@ export async function getPostById(postId: string): Promise<Post | undefined> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function createPost(input: CreatePostInput): Promise<Post> {
|
||||
return httpJson<Post>("/api/v1/posts", {
|
||||
method: "POST",
|
||||
cache: "no-store",
|
||||
json: {
|
||||
title: input.title,
|
||||
content: input.content,
|
||||
images: input.images,
|
||||
tags: input.tags,
|
||||
...(input.linkedOrderId ? { linkedOrderId: input.linkedOrderId } : {}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export async function listPostsByAuthor(userId: string, options?: ListOptions): Promise<Post[]> {
|
||||
const res = await httpJson<Paginated<Post>>(
|
||||
withOffsetLimit(`/api/v1/users/${encodeURIComponent(userId)}/posts`, options),
|
||||
|
||||
Reference in New Issue
Block a user