frontend fully integreated with the backend
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { api } from '@/lib/api'
|
||||
import type {
|
||||
PaginatedResponse,
|
||||
SaleResponse,
|
||||
OrderResponse,
|
||||
PaymentResponse,
|
||||
SaleStatus,
|
||||
OrderStatus,
|
||||
PaymentStatus,
|
||||
PaymentMethod,
|
||||
} from '@/types/api'
|
||||
|
||||
import type { PageParams } from './master'
|
||||
|
||||
// ─── Sales ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface SaleItemBody {
|
||||
itemId: string
|
||||
quantity: number
|
||||
unitPrice: number
|
||||
}
|
||||
|
||||
export interface SaleBody {
|
||||
storeId: string
|
||||
rideId?: string | null
|
||||
fulfillImmediately?: boolean
|
||||
items: SaleItemBody[]
|
||||
}
|
||||
|
||||
export interface SaleListParams extends PageParams {
|
||||
storeId?: string
|
||||
status?: SaleStatus
|
||||
paymentStatus?: PaymentStatus
|
||||
rideId?: string
|
||||
from?: string
|
||||
to?: string
|
||||
}
|
||||
|
||||
export const sales = {
|
||||
list: (params?: SaleListParams) =>
|
||||
api.get<PaginatedResponse<SaleResponse>>('/sales', { params }).then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<SaleResponse>(`/sales/${id}`).then(r => r.data),
|
||||
|
||||
create: (body: SaleBody) =>
|
||||
api.post<SaleResponse>('/sales', body).then(r => r.data),
|
||||
|
||||
cancel: (id: string) =>
|
||||
api.patch<SaleResponse>(`/sales/${id}/cancel`).then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Orders ───────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface OrderListParams extends PageParams {
|
||||
storeId?: string
|
||||
status?: OrderStatus
|
||||
from?: string
|
||||
to?: string
|
||||
}
|
||||
|
||||
export const orders = {
|
||||
list: (params?: OrderListParams) =>
|
||||
api.get<PaginatedResponse<OrderResponse>>('/orders', { params }).then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<OrderResponse>(`/orders/${id}`).then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Payments ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface PaymentBody {
|
||||
saleId: string
|
||||
storeId: string
|
||||
amount: number
|
||||
method: PaymentMethod
|
||||
collectedAt: string
|
||||
}
|
||||
|
||||
export interface PaymentListParams extends PageParams {
|
||||
storeId?: string
|
||||
saleId?: string
|
||||
method?: PaymentMethod
|
||||
from?: string
|
||||
to?: string
|
||||
}
|
||||
|
||||
export const payments = {
|
||||
list: (params?: PaymentListParams) =>
|
||||
api.get<PaginatedResponse<PaymentResponse>>('/payments', { params }).then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<PaymentResponse>(`/payments/${id}`).then(r => r.data),
|
||||
|
||||
create: (body: PaymentBody) =>
|
||||
api.post<PaymentResponse>('/payments', body).then(r => r.data),
|
||||
}
|
||||
Reference in New Issue
Block a user