Files
edr-platform/apps/edr-freight-web/backoffice/src/services/last-mile-requests.service.ts

52 lines
1.6 KiB
TypeScript

import { api } from '../auth/http';
import { URL_CONSTANTS } from '@/constants/URLS';
export const LAST_MILE_REQUEST_STATUSES = [
'AWAITING_CONFIRMATION',
'SUBMITTED',
'APPROVED',
'REJECTED',
] as const;
export type LastMileRequestStatus = (typeof LAST_MILE_REQUEST_STATUSES)[number];
export interface LastMileRequest {
id: string;
bookingId: string;
booking?: {
id: string;
reference?: string;
companyId?: string;
company?: { id: string; name?: string } | null;
} | null;
trainScheduleId: string;
status: LastMileRequestStatus;
requestedContainerNumbers?: string[] | null;
reminderSentAt?: string | null;
submittedByUserId?: string | null;
submittedAt?: string | null;
reviewedByStaffId?: string | null;
reviewedAt?: string | null;
rejectionReason?: string | null;
resultingLastMileId?: string | null;
createdAt: string;
updatedAt: string;
}
export interface LastMileRequestListResponse {
data: LastMileRequest[];
meta: { total: number; page: number; pageSize: number; totalPages: number };
}
const LMR = URL_CONSTANTS.LAST_MILE_REQUESTS;
export const lastMileRequestsService = {
list: (params?: { status?: LastMileRequestStatus; bookingId?: string; page?: number; pageSize?: number }) =>
api.get<LastMileRequestListResponse>(LMR.BASE, { params }),
getById: (id: string) => api.get<LastMileRequest>(LMR.BY_ID(id)),
freeTruckCount: () => api.get<{ count: number }>(LMR.FREE_TRUCK_COUNT),
approve: (id: string, advanceAmount: number) =>
api.post<LastMileRequest>(LMR.APPROVE(id), { advanceAmount }),
reject: (id: string, reason: string) =>
api.post<LastMileRequest>(LMR.REJECT(id), { reason }),
};