134 lines
4.3 KiB
TypeScript
134 lines
4.3 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PaginatedResponse,
|
|
RideResponse,
|
|
CancelRequestResponse,
|
|
LoadingSheetResponse,
|
|
DeliveryTaskResponse,
|
|
RideType,
|
|
RideStatus,
|
|
CancelRequestType,
|
|
CancelRequestStatus,
|
|
LoadingSheetStatus,
|
|
DeliveryTaskStatus,
|
|
} from '@/types/api'
|
|
|
|
import type { PageParams } from './master'
|
|
|
|
// ─── Rides ────────────────────────────────────────────────────────────────────
|
|
|
|
export interface RideBody {
|
|
rideType: RideType
|
|
vehicleId: string
|
|
driverProfileId: string
|
|
routeId: string
|
|
sourceWarehouseId: string
|
|
meterstart: number
|
|
}
|
|
|
|
export interface RideListParams extends PageParams {
|
|
status?: RideStatus
|
|
rideType?: RideType
|
|
driverProfileId?: string
|
|
vehicleId?: string
|
|
}
|
|
|
|
export interface CancelRequestBody {
|
|
typeCode: CancelRequestType
|
|
reason: string
|
|
}
|
|
|
|
export interface CancelRequestReviewBody {
|
|
status: CancelRequestStatus
|
|
}
|
|
|
|
export const rides = {
|
|
list: (params?: RideListParams) =>
|
|
api.get<PaginatedResponse<RideResponse>>('/rides', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<RideResponse>(`/rides/${id}`).then(r => r.data),
|
|
|
|
create: (body: RideBody) =>
|
|
api.post<RideResponse>('/rides', body).then(r => r.data),
|
|
|
|
activate: (id: string) =>
|
|
api.patch<RideResponse>(`/rides/${id}/activate`).then(r => r.data),
|
|
|
|
close: (id: string, meterend: number) =>
|
|
api.patch<RideResponse>(`/rides/${id}/close`, { meterend }).then(r => r.data),
|
|
|
|
cancelRequests: {
|
|
list: (rideId: string) =>
|
|
api.get<CancelRequestResponse[]>(`/rides/${rideId}/cancel-requests`).then(r => r.data),
|
|
|
|
create: (rideId: string, body: CancelRequestBody) =>
|
|
api.post<CancelRequestResponse>(`/rides/${rideId}/cancel-requests`, body).then(r => r.data),
|
|
|
|
review: (rideId: string, requestId: string, body: CancelRequestReviewBody) =>
|
|
api.patch<CancelRequestResponse>(`/rides/${rideId}/cancel-requests/${requestId}`, body).then(r => r.data),
|
|
},
|
|
}
|
|
|
|
// ─── Loading Sheets ───────────────────────────────────────────────────────────
|
|
|
|
export interface LoadingSheetItemBody {
|
|
itemId: string
|
|
quantityDispatched: number
|
|
}
|
|
|
|
export interface LoadingSheetBody {
|
|
rideId: string
|
|
sourceWarehouseId: string
|
|
items: LoadingSheetItemBody[]
|
|
}
|
|
|
|
export interface LoadingSheetReceiptItemBody {
|
|
itemId: string
|
|
quantityReceived: number
|
|
}
|
|
|
|
export interface LoadingSheetListParams extends PageParams {
|
|
rideId?: string
|
|
status?: LoadingSheetStatus
|
|
}
|
|
|
|
export const loadingSheets = {
|
|
list: (params?: LoadingSheetListParams) =>
|
|
api.get<PaginatedResponse<LoadingSheetResponse>>('/loading-sheets', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<LoadingSheetResponse>(`/loading-sheets/${id}`).then(r => r.data),
|
|
|
|
create: (body: LoadingSheetBody) =>
|
|
api.post<LoadingSheetResponse>('/loading-sheets', body).then(r => r.data),
|
|
|
|
confirmDispatch: (id: string) =>
|
|
api.patch<LoadingSheetResponse>(`/loading-sheets/${id}/dispatch`).then(r => r.data),
|
|
|
|
confirmReceipt: (id: string, items: LoadingSheetReceiptItemBody[]) =>
|
|
api.patch<LoadingSheetResponse>(`/loading-sheets/${id}/receipt`, { items }).then(r => r.data),
|
|
|
|
resolve: (id: string) =>
|
|
api.patch<LoadingSheetResponse>(`/loading-sheets/${id}/resolve`).then(r => r.data),
|
|
}
|
|
|
|
// ─── Delivery Tasks ───────────────────────────────────────────────────────────
|
|
|
|
export interface DeliveryTaskListParams extends PageParams {
|
|
rideId?: string
|
|
status?: DeliveryTaskStatus
|
|
storeId?: string
|
|
}
|
|
|
|
export const deliveryTasks = {
|
|
listByRide: (rideId: string, params?: Omit<DeliveryTaskListParams, 'rideId'>) =>
|
|
api.get<PaginatedResponse<DeliveryTaskResponse>>(`/rides/${rideId}/delivery-tasks`, { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<DeliveryTaskResponse>(`/delivery-tasks/${id}`).then(r => r.data),
|
|
|
|
updateStatus: (id: string, status: DeliveryTaskStatus, note?: string) =>
|
|
api.patch<DeliveryTaskResponse>(`/delivery-tasks/${id}/status`, { status, note }).then(r => r.data),
|
|
}
|