From 1f20198f23c2c756a45f63079e1c08b9ac487dcf Mon Sep 17 00:00:00 2001 From: zetaloop Date: Fri, 1 May 2026 04:23:57 +0800 Subject: [PATCH] fix(api): remove unused listOrdersByConsumer helper The function performed client-side filtering on top of listOrders but was never called by any page. listPlayersByShop is kept as-is since the backend has no dedicated shop players endpoint. --- lib/api/index.ts | 2 +- lib/api/orders.ts | 23 ++++++++++++++--------- tests/orders-api.test.ts | 7 +++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/api/index.ts b/lib/api/index.ts index 06f9e25..f8947fa 100644 --- a/lib/api/index.ts +++ b/lib/api/index.ts @@ -13,7 +13,7 @@ export { markAllNotificationsAsRead, markNotificationAsRead, } from "./notifications" -export { getOrderById, listOrders, listOrdersByConsumer } from "./orders" +export { getOrderById, listOrders } from "./orders" export { getPlayerById, listPlayers, listPlayersByShop } from "./players" export { createPost, getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts" export { listReviews, listReviewsByOrder, listReviewsByTargetUser } from "./reviews" diff --git a/lib/api/orders.ts b/lib/api/orders.ts index 433ed98..c07537b 100644 --- a/lib/api/orders.ts +++ b/lib/api/orders.ts @@ -79,25 +79,30 @@ export async function getOrderById(orderId: string): Promise } } -export async function listOrdersByConsumer(consumerId: string): Promise { - const items = await listOrders({ role: "consumer" }) - return items.filter((order) => order.consumerId === consumerId) -} - interface CreatePaidOrderInput { - playerId: string - serviceId: string - shopId?: string + playerId: string | number + serviceId: string | number + shopId?: string | number quantity: number note?: string } +function createOrderJson(input: CreatePaidOrderInput) { + return { + playerId: Number(input.playerId), + serviceId: Number(input.serviceId), + ...(input.shopId ? { shopId: Number(input.shopId) } : {}), + quantity: input.quantity, + ...(input.note ? { note: input.note } : {}), + } +} + export async function createPaidOrder(input: CreatePaidOrderInput): Promise { try { const res = await httpJson("/api/v1/orders/paid", { method: "POST", cache: "no-store", - json: input, + json: createOrderJson(input), }) const order = unwrapOrder(res) if (!order) { diff --git a/tests/orders-api.test.ts b/tests/orders-api.test.ts index 40ded67..a755f87 100644 --- a/tests/orders-api.test.ts +++ b/tests/orders-api.test.ts @@ -21,6 +21,13 @@ describe("lib/api/orders", () => { quantity: 1, }) + expect(fetch).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + body: JSON.stringify({ playerId: 1005, serviceId: 5001, quantity: 1 }), + }), + ) + expect(res).toEqual({ decision: { ok: false,