82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { apiClient } from './client'
|
|
|
|
export interface Order {
|
|
id: number
|
|
order_no: string
|
|
listing_id: number
|
|
account_id: number
|
|
owner_id: number
|
|
renter_id: number
|
|
title: string
|
|
server_region: string
|
|
login_platform: string
|
|
rent_start_at?: string
|
|
rent_end_at?: string
|
|
rent_hours: number
|
|
rent_amount: number
|
|
deposit_amount: number
|
|
platform_fee: number
|
|
account_snapshot?: Record<string, unknown>
|
|
status: string
|
|
handoff_status: string
|
|
settlement_status: string
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface HandoffRecord {
|
|
id: number
|
|
order_id: number
|
|
from_user_id: number
|
|
to_user_id: number
|
|
type: string
|
|
content: string
|
|
confirmed_by_renter_at?: string
|
|
confirmed_by_owner_at?: string
|
|
created_at: string
|
|
}
|
|
|
|
interface ApiResponse<T> {
|
|
code: string
|
|
message: string
|
|
data: T
|
|
}
|
|
|
|
export async function createOrder(listingId: number, rentHours: number) {
|
|
const { data } = await apiClient.post<ApiResponse<Order>>('/orders', {
|
|
listing_id: listingId,
|
|
rent_hours: rentHours,
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchOrders() {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: Order[] }>>('/orders')
|
|
return data.data.items
|
|
}
|
|
|
|
export async function fetchOrder(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<Order>>(`/orders/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function cancelOrder(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<{ cancelled: boolean }>>(`/orders/${id}/cancel`)
|
|
return data.data
|
|
}
|
|
|
|
export async function submitHandoff(id: number, content: string) {
|
|
const { data } = await apiClient.post<ApiResponse<HandoffRecord>>(`/orders/${id}/handoff`, { content })
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchHandoffRecords(id: string | number) {
|
|
const { data } = await apiClient.get<ApiResponse<{ items: HandoffRecord[] }>>(`/orders/${id}/handoff-records`)
|
|
return data.data.items
|
|
}
|
|
|
|
export async function confirmReceive(id: number) {
|
|
const { data } = await apiClient.post<ApiResponse<{ received: boolean }>>(`/orders/${id}/confirm-receive`)
|
|
return data.data
|
|
}
|