mirror of
https://git.meshkee.com/BaloutPastry/dashboards.git
synced 2026-08-11 22:30:59 +04:30
Wire dashboards to the API and add customer portal plus discounts.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
af11d96fd0
commit
b103e330ef
@@ -0,0 +1,73 @@
|
||||
import type { Order, OrderStatus } from '../data/orders'
|
||||
import { apiRequest } from './api'
|
||||
|
||||
export type OrderListResponse = {
|
||||
items: Order[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export type ListOrdersParams = {
|
||||
q?: string
|
||||
status?: OrderStatus | ''
|
||||
customerId?: string
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export type CreateOrderItemPayload = {
|
||||
productId: string
|
||||
quantity: number
|
||||
optionIds?: string[]
|
||||
}
|
||||
|
||||
export type CreateOrderPayload = {
|
||||
customerId: string
|
||||
deliveryType: 'pickup' | 'shipping'
|
||||
branchId?: string
|
||||
shippingAddressId?: string
|
||||
note?: string
|
||||
items: CreateOrderItemPayload[]
|
||||
}
|
||||
|
||||
function buildQuery(params: ListOrdersParams) {
|
||||
const search = new URLSearchParams()
|
||||
if (params.q?.trim()) search.set('q', params.q.trim())
|
||||
if (params.status) search.set('status', params.status)
|
||||
if (params.customerId) search.set('customerId', params.customerId)
|
||||
if (params.page) search.set('page', String(params.page))
|
||||
if (params.pageSize) search.set('pageSize', String(params.pageSize))
|
||||
const qs = search.toString()
|
||||
return qs ? `?${qs}` : ''
|
||||
}
|
||||
|
||||
export function listOrders(params: ListOrdersParams = {}) {
|
||||
return apiRequest<OrderListResponse>(`/orders${buildQuery(params)}`)
|
||||
}
|
||||
|
||||
export function listMyOrders(params: ListOrdersParams = {}) {
|
||||
return apiRequest<OrderListResponse>(`/orders/mine${buildQuery(params)}`)
|
||||
}
|
||||
|
||||
export function getOrder(id: string) {
|
||||
return apiRequest<Order>(`/orders/${id}`)
|
||||
}
|
||||
|
||||
export function getMyOrder(id: string) {
|
||||
return apiRequest<Order>(`/orders/mine/${id}`)
|
||||
}
|
||||
|
||||
export function createOrder(payload: CreateOrderPayload) {
|
||||
return apiRequest<Order>('/orders', {
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
})
|
||||
}
|
||||
|
||||
export function updateOrderStatus(id: string, status: OrderStatus) {
|
||||
return apiRequest<Order>(`/orders/${id}/status`, {
|
||||
method: 'PATCH',
|
||||
body: { status },
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user