mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 08:25:43 +00:00
feat(bookings): Integrate booking list and detail pages with backend API
This commit is contained in:
@@ -27,6 +27,8 @@ import {
|
||||
ruleEngineService,
|
||||
RuleEngineListParams,
|
||||
} from "./ruleEngine/ruleEngine.service";
|
||||
import { bookingsService, BookingListFilter } from "./bookings.service";
|
||||
import type { Freight, PaginatedResponse } from "@edr/types";
|
||||
|
||||
export const api = {
|
||||
fileUploadSettings: {
|
||||
@@ -220,4 +222,30 @@ export const api = {
|
||||
() => ruleEngineService.getApprovalChain(),
|
||||
),
|
||||
},
|
||||
|
||||
bookings: {
|
||||
list: endpoint<
|
||||
{ filter?: BookingListFilter },
|
||||
PaginatedResponse<Freight.IBooking>
|
||||
>("bookings", "list", ({ filter }) => bookingsService.list(filter)),
|
||||
|
||||
getById: endpoint<{ id: string }, Freight.IBooking>(
|
||||
"bookings",
|
||||
"getById",
|
||||
({ id }) => bookingsService.getById(id),
|
||||
),
|
||||
|
||||
updateStatus: endpoint<
|
||||
{ id: string; action: string; reason?: string },
|
||||
Freight.IBooking
|
||||
>("bookings", "updateStatus", ({ id, action, reason }) =>
|
||||
bookingsService.updateStatus(id, { action, reason }),
|
||||
),
|
||||
|
||||
remove: endpoint<{ id: string }, void>(
|
||||
"bookings",
|
||||
"remove",
|
||||
({ id }) => bookingsService.remove(id),
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { Freight, PaginatedResponse } from "@edr/types";
|
||||
|
||||
import { api as client } from "../auth/http";
|
||||
import { unwrap } from "@/utils/endpoint";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
|
||||
const BASE = URL_CONSTANTS.BOOKINGS.BASE;
|
||||
|
||||
export interface BookingListFilter {
|
||||
status?: string;
|
||||
customerId?: string;
|
||||
search?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
sortBy?: string;
|
||||
sortOrder?: "ASC" | "DESC";
|
||||
}
|
||||
|
||||
export const bookingsService = {
|
||||
list: async (
|
||||
filter?: BookingListFilter,
|
||||
): Promise<PaginatedResponse<Freight.IBooking>> => {
|
||||
const response = await client.get<PaginatedResponse<Freight.IBooking>>(
|
||||
BASE,
|
||||
{ params: filter },
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
getById: async (id: string): Promise<Freight.IBooking> => {
|
||||
const response = await client.get<Freight.IBooking>(
|
||||
URL_CONSTANTS.BOOKINGS.BY_ID(id),
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
updateStatus: async (
|
||||
id: string,
|
||||
payload: { action: string; reason?: string },
|
||||
): Promise<Freight.IBooking> => {
|
||||
const response = await client.patch<Freight.IBooking>(
|
||||
`${URL_CONSTANTS.BOOKINGS.BY_ID(id)}/status`,
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
remove: async (id: string): Promise<void> => {
|
||||
await client.delete(URL_CONSTANTS.BOOKINGS.BY_ID(id));
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user