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.
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ export {
|
|||||||
markAllNotificationsAsRead,
|
markAllNotificationsAsRead,
|
||||||
markNotificationAsRead,
|
markNotificationAsRead,
|
||||||
} from "./notifications"
|
} from "./notifications"
|
||||||
export { getOrderById, listOrders, listOrdersByConsumer } from "./orders"
|
export { getOrderById, listOrders } from "./orders"
|
||||||
export { getPlayerById, listPlayers, listPlayersByShop } from "./players"
|
export { getPlayerById, listPlayers, listPlayersByShop } from "./players"
|
||||||
export { createPost, getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts"
|
export { createPost, getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts"
|
||||||
export { listReviews, listReviewsByOrder, listReviewsByTargetUser } from "./reviews"
|
export { listReviews, listReviewsByOrder, listReviewsByTargetUser } from "./reviews"
|
||||||
|
|||||||
+14
-9
@@ -79,25 +79,30 @@ export async function getOrderById(orderId: string): Promise<Order | undefined>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listOrdersByConsumer(consumerId: string): Promise<Order[]> {
|
|
||||||
const items = await listOrders({ role: "consumer" })
|
|
||||||
return items.filter((order) => order.consumerId === consumerId)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CreatePaidOrderInput {
|
interface CreatePaidOrderInput {
|
||||||
playerId: string
|
playerId: string | number
|
||||||
serviceId: string
|
serviceId: string | number
|
||||||
shopId?: string
|
shopId?: string | number
|
||||||
quantity: number
|
quantity: number
|
||||||
note?: string
|
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<ActionResult> {
|
export async function createPaidOrder(input: CreatePaidOrderInput): Promise<ActionResult> {
|
||||||
try {
|
try {
|
||||||
const res = await httpJson<unknown>("/api/v1/orders/paid", {
|
const res = await httpJson<unknown>("/api/v1/orders/paid", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
json: input,
|
json: createOrderJson(input),
|
||||||
})
|
})
|
||||||
const order = unwrapOrder(res)
|
const order = unwrapOrder(res)
|
||||||
if (!order) {
|
if (!order) {
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ describe("lib/api/orders", () => {
|
|||||||
quantity: 1,
|
quantity: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
expect(fetch).toHaveBeenCalledWith(
|
||||||
|
expect.any(String),
|
||||||
|
expect.objectContaining({
|
||||||
|
body: JSON.stringify({ playerId: 1005, serviceId: 5001, quantity: 1 }),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
expect(res).toEqual({
|
expect(res).toEqual({
|
||||||
decision: {
|
decision: {
|
||||||
ok: false,
|
ok: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user