mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 14:08:11 +00:00
Merge freight/develop into feature/trains-management
This commit is contained in:
338
apps/edr-freight-web/backoffice/src/services/api.ts
Normal file
338
apps/edr-freight-web/backoffice/src/services/api.ts
Normal file
@@ -0,0 +1,338 @@
|
||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||
import { endpoint } from "@/utils/endpoint";
|
||||
import type {
|
||||
CreateFileUploadFieldDto,
|
||||
CreateFileUploadSettingDto,
|
||||
FileUploadField,
|
||||
FileUploadSetting,
|
||||
UpdateFileUploadFieldDto,
|
||||
UpdateFileUploadSettingDto,
|
||||
} from "@/types/fileUploadSettings";
|
||||
import {
|
||||
CreateDropdownOptionDto,
|
||||
CreateDropdownSettingDto,
|
||||
DropdownOption,
|
||||
DropdownSetting,
|
||||
UpdateDropdownOptionDto,
|
||||
UpdateDropdownSettingDto,
|
||||
} from "@/types/dropdownSettings";
|
||||
import {
|
||||
RuleEngineListResult,
|
||||
RuleEngineRecord,
|
||||
RuleEngineResourceSlug,
|
||||
} from "@/types/rule-engine";
|
||||
import { fileUploadSettingsService } from "./fileUploadSettings.service";
|
||||
import { dropdownSettingsService } from "./dropdownSettings.service";
|
||||
import {
|
||||
ruleEngineService,
|
||||
RuleEngineListParams,
|
||||
} from "./ruleEngine/ruleEngine.service";
|
||||
import {
|
||||
bookingsService,
|
||||
BookingListFilter,
|
||||
type ApproveStepPayload,
|
||||
type PaginatedBookings,
|
||||
type RejectStepPayload,
|
||||
} from "./bookings.service";
|
||||
import type { BookingDetail } from "@/types/booking";
|
||||
|
||||
export const api = {
|
||||
fileUploadSettings: {
|
||||
list: endpoint<void, FileUploadSetting[]>(
|
||||
"file-upload-settings",
|
||||
"list",
|
||||
fileUploadSettingsService.list,
|
||||
),
|
||||
|
||||
getById: endpoint<{ id: string }, FileUploadSetting>(
|
||||
"file-upload-settings",
|
||||
"getById",
|
||||
({ id }) => fileUploadSettingsService.getById(id),
|
||||
),
|
||||
|
||||
getByCode: endpoint<{ code: string }, FileUploadSetting>(
|
||||
"file-upload-settings",
|
||||
"getByCode",
|
||||
({ code }) => fileUploadSettingsService.getByCode(code),
|
||||
),
|
||||
|
||||
create: endpoint<CreateFileUploadSettingDto, FileUploadSetting>(
|
||||
"file-upload-settings",
|
||||
"create",
|
||||
(payload) => fileUploadSettingsService.create(payload),
|
||||
),
|
||||
|
||||
update: endpoint<
|
||||
{ id: string; dto: UpdateFileUploadSettingDto },
|
||||
FileUploadSetting
|
||||
>("file-upload-settings", "update", ({ id, dto }) =>
|
||||
fileUploadSettingsService.update(id, dto),
|
||||
),
|
||||
|
||||
remove: endpoint<{ id: string }, void>(
|
||||
"file-upload-settings",
|
||||
"remove",
|
||||
({ id }) => fileUploadSettingsService.remove(id),
|
||||
),
|
||||
|
||||
replaceFields: endpoint<
|
||||
{ id: string; fields: CreateFileUploadFieldDto[] },
|
||||
FileUploadField[]
|
||||
>("file-upload-settings", "replaceFields", ({ id, fields }) =>
|
||||
fileUploadSettingsService.replaceFields(id, fields),
|
||||
),
|
||||
|
||||
addField: endpoint<
|
||||
{ settingId: string; dto: CreateFileUploadFieldDto },
|
||||
FileUploadField
|
||||
>("file-upload-settings", "addField", ({ settingId, dto }) =>
|
||||
fileUploadSettingsService.addField(settingId, dto),
|
||||
),
|
||||
|
||||
updateField: endpoint<
|
||||
{ fieldId: string; dto: UpdateFileUploadFieldDto },
|
||||
FileUploadField
|
||||
>("file-upload-settings", "updateField", ({ fieldId, dto }) =>
|
||||
fileUploadSettingsService.updateField(fieldId, dto),
|
||||
),
|
||||
|
||||
removeField: endpoint<{ fieldId: string }, void>(
|
||||
"file-upload-settings",
|
||||
"removeField",
|
||||
({ fieldId }) => fileUploadSettingsService.removeField(fieldId),
|
||||
),
|
||||
},
|
||||
|
||||
dropdownSettings: {
|
||||
list: endpoint<void, DropdownSetting[]>(
|
||||
"dropdown-settings",
|
||||
"list",
|
||||
dropdownSettingsService.list,
|
||||
),
|
||||
|
||||
getById: endpoint<{ id: string }, DropdownSetting>(
|
||||
"dropdown-settings",
|
||||
"getById",
|
||||
({ id }) => dropdownSettingsService.getById(id),
|
||||
),
|
||||
|
||||
getByCode: endpoint<{ code: string }, DropdownSetting>(
|
||||
"dropdown-settings",
|
||||
"getByCode",
|
||||
({ code }) => dropdownSettingsService.getByCode(code),
|
||||
),
|
||||
|
||||
create: endpoint<CreateDropdownSettingDto, DropdownSetting>(
|
||||
"dropdown-settings",
|
||||
"create",
|
||||
(payload) => dropdownSettingsService.create(payload),
|
||||
),
|
||||
|
||||
update: endpoint<
|
||||
{ id: string; dto: UpdateDropdownSettingDto },
|
||||
DropdownSetting
|
||||
>("dropdown-settings", "update", ({ id, dto }) =>
|
||||
dropdownSettingsService.update(id, dto),
|
||||
),
|
||||
|
||||
remove: endpoint<{ id: string }, void>(
|
||||
"dropdown-settings",
|
||||
"remove",
|
||||
({ id }) => dropdownSettingsService.remove(id),
|
||||
),
|
||||
|
||||
replaceOptions: endpoint<
|
||||
{ id: string; options: CreateDropdownOptionDto[] },
|
||||
DropdownOption[]
|
||||
>("dropdown-settings", "replaceOptions", ({ id, options }) =>
|
||||
dropdownSettingsService.replaceOptions(id, options),
|
||||
),
|
||||
|
||||
addOption: endpoint<
|
||||
{ id: string; dto: CreateDropdownOptionDto },
|
||||
DropdownOption
|
||||
>("dropdown-settings", "addOption", ({ id, dto }) =>
|
||||
dropdownSettingsService.addOption(id, dto),
|
||||
),
|
||||
|
||||
updateOption: endpoint<
|
||||
{ optionId: string; dto: UpdateDropdownOptionDto },
|
||||
DropdownOption
|
||||
>("dropdown-settings", "updateOption", ({ optionId, dto }) =>
|
||||
dropdownSettingsService.updateOption(optionId, dto),
|
||||
),
|
||||
|
||||
removeOption: endpoint<{ optionId: string }, void>(
|
||||
"dropdown-settings",
|
||||
"removeOption",
|
||||
({ optionId }) => dropdownSettingsService.removeOption(optionId),
|
||||
),
|
||||
},
|
||||
|
||||
ruleEngine: {
|
||||
list: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; params?: RuleEngineListParams },
|
||||
RuleEngineListResult<RuleEngineRecord>
|
||||
>(
|
||||
"rule-engine",
|
||||
"list",
|
||||
({ resource, params }) => ruleEngineService.list(resource, params),
|
||||
({ resource, params }) => QUERY_KEYS.RULE_ENGINE.list(resource, params),
|
||||
),
|
||||
|
||||
getById: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; id: string },
|
||||
RuleEngineRecord
|
||||
>(
|
||||
"rule-engine",
|
||||
"getById",
|
||||
({ resource, id }) => ruleEngineService.getById(resource, id),
|
||||
({ resource, id }) => QUERY_KEYS.RULE_ENGINE.detail(resource, id),
|
||||
),
|
||||
|
||||
create: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; payload: Record<string, unknown> },
|
||||
RuleEngineRecord
|
||||
>("rule-engine", "create", ({ resource, payload }) =>
|
||||
ruleEngineService.create(resource, payload),
|
||||
),
|
||||
|
||||
update: endpoint<
|
||||
{
|
||||
resource: RuleEngineResourceSlug;
|
||||
id: string;
|
||||
payload: Record<string, unknown>;
|
||||
},
|
||||
RuleEngineRecord
|
||||
>("rule-engine", "update", ({ resource, id, payload }) =>
|
||||
ruleEngineService.update(resource, id, payload),
|
||||
),
|
||||
|
||||
remove: endpoint<
|
||||
{ resource: RuleEngineResourceSlug; id: string },
|
||||
void
|
||||
>("rule-engine", "remove", ({ resource, id }) =>
|
||||
ruleEngineService.remove(resource, id),
|
||||
),
|
||||
|
||||
submitRate: endpoint<{ id: string }, RuleEngineRecord>(
|
||||
"rule-engine",
|
||||
"submitRate",
|
||||
({ id }) => ruleEngineService.submitRate(id),
|
||||
),
|
||||
|
||||
approveRate: endpoint<{ id: string }, RuleEngineRecord>(
|
||||
"rule-engine",
|
||||
"approveRate",
|
||||
({ id }) => ruleEngineService.approveRate(id),
|
||||
),
|
||||
|
||||
getApprovalChain: endpoint<void, RuleEngineRecord[]>(
|
||||
"rule-engine",
|
||||
"getApprovalChain",
|
||||
() => ruleEngineService.getApprovalChain(),
|
||||
() => QUERY_KEYS.RULE_ENGINE.chain,
|
||||
),
|
||||
},
|
||||
|
||||
bookings: {
|
||||
list: endpoint<{ filter?: BookingListFilter }, PaginatedBookings>(
|
||||
"bookings",
|
||||
"list",
|
||||
({ filter }) => bookingsService.list(filter),
|
||||
({ filter }) => QUERY_KEYS.BOOKINGS.list(filter),
|
||||
),
|
||||
|
||||
getById: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"getById",
|
||||
({ id }) => bookingsService.getById(id),
|
||||
({ id }) => QUERY_KEYS.BOOKINGS.byId(id),
|
||||
),
|
||||
|
||||
remove: endpoint<{ id: string }, void>(
|
||||
"bookings",
|
||||
"remove",
|
||||
({ id }) => bookingsService.remove(id),
|
||||
),
|
||||
|
||||
staffAccept: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"staffAccept",
|
||||
({ id }) => bookingsService.staffAccept(id),
|
||||
),
|
||||
|
||||
requestChanges: endpoint<{ id: string; note: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"requestChanges",
|
||||
({ id, note }) => bookingsService.requestChanges(id, note),
|
||||
),
|
||||
|
||||
staffReject: endpoint<{ id: string; reason: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"staffReject",
|
||||
({ id, reason }) => bookingsService.staffReject(id, reason),
|
||||
),
|
||||
|
||||
approveStep: endpoint<ApproveStepPayload, BookingDetail>(
|
||||
"bookings",
|
||||
"approveStep",
|
||||
(payload) => bookingsService.approveStep(payload),
|
||||
),
|
||||
|
||||
rejectStep: endpoint<RejectStepPayload, BookingDetail>(
|
||||
"bookings",
|
||||
"rejectStep",
|
||||
(payload) => bookingsService.rejectStep(payload),
|
||||
),
|
||||
|
||||
generateContract: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"generateContract",
|
||||
({ id }) => bookingsService.generateContract(id),
|
||||
),
|
||||
|
||||
getContractView: endpoint<{ id: string }, import("./bookings.service").ContractView>(
|
||||
"bookings",
|
||||
"getContractView",
|
||||
({ id }) => bookingsService.getContractView(id),
|
||||
),
|
||||
|
||||
signContract: endpoint<
|
||||
{ id: string } & import("./bookings.service").SignContractPayload,
|
||||
BookingDetail
|
||||
>("bookings", "signContract", ({ id, ...payload }) =>
|
||||
bookingsService.signContract(id, payload),
|
||||
),
|
||||
|
||||
generatePnr: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"generatePnr",
|
||||
({ id }) => bookingsService.generatePnr(id),
|
||||
),
|
||||
|
||||
verifyPayment: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"verifyPayment",
|
||||
({ id }) => bookingsService.verifyPayment(id),
|
||||
),
|
||||
|
||||
startTransit: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"startTransit",
|
||||
({ id }) => bookingsService.startTransit(id),
|
||||
),
|
||||
|
||||
complete: endpoint<{ id: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"complete",
|
||||
({ id }) => bookingsService.complete(id),
|
||||
),
|
||||
|
||||
cancel: endpoint<{ id: string; reason: string }, BookingDetail>(
|
||||
"bookings",
|
||||
"cancel",
|
||||
({ id, reason }) => bookingsService.cancel(id, reason),
|
||||
),
|
||||
},
|
||||
};
|
||||
173
apps/edr-freight-web/backoffice/src/services/bookings.service.ts
Normal file
173
apps/edr-freight-web/backoffice/src/services/bookings.service.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
import { api as client } from "../auth/http";
|
||||
import { unwrap } from "@/utils/endpoint";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
import type { BookingDetail } from "@/types/booking";
|
||||
|
||||
const B = URL_CONSTANTS.BOOKINGS;
|
||||
|
||||
export interface BookingListFilter {
|
||||
status?: string;
|
||||
// customerId?: string;
|
||||
companyId?: string;
|
||||
freightType?: string;
|
||||
tradeDirection?: string;
|
||||
paymentCurrency?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
sortBy?: string;
|
||||
sortOrder?: "ASC" | "DESC";
|
||||
}
|
||||
|
||||
export interface PaginatedBookings {
|
||||
items: BookingDetail[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface ApproveStepPayload {
|
||||
id: string;
|
||||
stepId: string;
|
||||
requiredRole: string;
|
||||
}
|
||||
|
||||
export interface RejectStepPayload {
|
||||
id: string;
|
||||
stepId: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface ContractView {
|
||||
bookingId: string;
|
||||
reference: string;
|
||||
status: string;
|
||||
templateKey: string;
|
||||
title: string;
|
||||
html: string;
|
||||
canSignCustomer: boolean;
|
||||
canSignStaff: boolean;
|
||||
hasContractDocument: boolean;
|
||||
signatures: Array<{
|
||||
role: string;
|
||||
signerDisplayName: string;
|
||||
signedAt: string;
|
||||
signatureImageUrl?: string | null;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface SignContractPayload {
|
||||
role: "CUSTOMER" | "STAFF";
|
||||
signatureImageBase64: string;
|
||||
signerDisplayName: string;
|
||||
consentText?: string;
|
||||
}
|
||||
|
||||
async function postBooking<T>(url: string, body?: unknown): Promise<T> {
|
||||
const response = await client.post<T>(url, body ?? {});
|
||||
return unwrap(response.data);
|
||||
}
|
||||
|
||||
export const bookingsService = {
|
||||
list: async (filter?: BookingListFilter): Promise<PaginatedBookings> => {
|
||||
const response = await client.get<PaginatedBookings>(B.BASE, {
|
||||
params: filter,
|
||||
});
|
||||
const data = unwrap(response.data);
|
||||
return {
|
||||
items: (data.items ?? []) as BookingDetail[],
|
||||
total: data.total ?? 0,
|
||||
};
|
||||
},
|
||||
|
||||
getById: async (id: string): Promise<BookingDetail> => {
|
||||
const response = await client.get<BookingDetail>(B.BY_ID(id));
|
||||
return unwrap(response.data) as BookingDetail;
|
||||
},
|
||||
|
||||
remove: async (id: string): Promise<void> => {
|
||||
await client.delete(B.BY_ID(id));
|
||||
},
|
||||
|
||||
staffAccept: (id: string) => postBooking<BookingDetail>(B.STAFF_ACCEPT(id)),
|
||||
|
||||
requestChanges: (id: string, note: string) =>
|
||||
postBooking<BookingDetail>(B.STAFF_REQUEST_CHANGES(id), { note }),
|
||||
|
||||
staffReject: (id: string, reason: string) =>
|
||||
postBooking<BookingDetail>(B.STAFF_REJECT(id), { reason }),
|
||||
|
||||
approveStep: ({ id, stepId, requiredRole }: ApproveStepPayload) =>
|
||||
postBooking<BookingDetail>(B.APPROVE_STEP(id, stepId), { requiredRole }),
|
||||
|
||||
rejectStep: ({ id, stepId, reason }: RejectStepPayload) =>
|
||||
postBooking<BookingDetail>(B.REJECT_STEP(id, stepId), { reason }),
|
||||
|
||||
generateContract: (id: string) =>
|
||||
postBooking<BookingDetail>(B.CONTRACT_GENERATE(id)),
|
||||
|
||||
getContractView: async (id: string): Promise<ContractView> => {
|
||||
const response = await client.get<ContractView>(B.CONTRACT_VIEW(id));
|
||||
return unwrap(response.data) as ContractView;
|
||||
},
|
||||
|
||||
downloadContract: async (id: string): Promise<Blob> => {
|
||||
const response = await client.get(B.CONTRACT_DOWNLOAD(id), {
|
||||
responseType: "blob",
|
||||
});
|
||||
return response.data as Blob;
|
||||
},
|
||||
|
||||
downloadContractDocument: async (id: string): Promise<Blob> => {
|
||||
const response = await client.get(B.CONTRACT_DOCUMENT(id), {
|
||||
responseType: "blob",
|
||||
});
|
||||
return response.data as Blob;
|
||||
},
|
||||
|
||||
signContract: (id: string, payload: SignContractPayload) =>
|
||||
postBooking<BookingDetail>(B.CONTRACT_SIGN(id), payload),
|
||||
|
||||
getSummary: async (id: string): Promise<{ summary: string }> => {
|
||||
const response = await client.get<{ summary: string }>(B.SUMMARY(id));
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
customerSign: (id: string, payload: SignContractPayload) =>
|
||||
postBooking<BookingDetail>(B.CUSTOMER_SIGN(id), {
|
||||
...payload,
|
||||
role: "CUSTOMER",
|
||||
}),
|
||||
|
||||
marketingApprove: (id: string, payload: SignContractPayload) =>
|
||||
postBooking<BookingDetail>(B.MARKETING_APPROVE(id), {
|
||||
...payload,
|
||||
role: "STAFF",
|
||||
}),
|
||||
|
||||
generatePnr: (id: string) => postBooking<BookingDetail>(B.PAYMENT_PNR(id)),
|
||||
|
||||
submitPaymentProof: async (id: string, file: File): Promise<BookingDetail> => {
|
||||
const form = new FormData();
|
||||
form.append("file", file);
|
||||
const response = await client.post<BookingDetail>(B.PAYMENT_PROOF(id), form, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
return unwrap(response.data) as BookingDetail;
|
||||
},
|
||||
|
||||
verifyPayment: (id: string) =>
|
||||
postBooking<BookingDetail>(B.PAYMENT_VERIFY(id)),
|
||||
|
||||
downloadPaymentRequestLetter: async (id: string): Promise<Blob> => {
|
||||
const response = await client.get(B.PAYMENT_REQUEST_LETTER(id), {
|
||||
responseType: "blob",
|
||||
});
|
||||
return response.data as Blob;
|
||||
},
|
||||
|
||||
startTransit: (id: string) =>
|
||||
postBooking<BookingDetail>(B.START_TRANSIT(id)),
|
||||
|
||||
complete: (id: string) => postBooking<BookingDetail>(B.COMPLETE(id)),
|
||||
|
||||
cancel: (id: string, reason: string) =>
|
||||
postBooking<BookingDetail>(B.CANCEL(id), { reason }),
|
||||
};
|
||||
@@ -23,4 +23,4 @@ export const cargoService = {
|
||||
apiClient.post(`/cargoes/${cargoId}/load`, { quantity, weight, volume }),
|
||||
deliver: (cargoId: string) => apiClient.post(`/cargoes/${cargoId}/deliver`),
|
||||
unload: (cargoId: string) => apiClient.post(`/cargoes/${cargoId}/unload`),
|
||||
};
|
||||
};
|
||||
@@ -8,10 +8,8 @@ import type {
|
||||
UpdateFileUploadFieldDto,
|
||||
UpdateFileUploadSettingDto,
|
||||
} from "@/types/fileUploadSettings";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
import { QUERY_KEYS } from "@/constants/TANSTACK_QUEY_KEY";
|
||||
import { ApiResponse } from "@/types/apiResponse";
|
||||
import { endpoint, unwrap } from "@/utils/endpoint";
|
||||
import { unwrap } from "@/utils/endpoint";
|
||||
|
||||
const BASE = "/file-upload-settings";
|
||||
|
||||
@@ -124,14 +122,3 @@ export const fileUploadSettingsService = {
|
||||
await client.delete(`${BASE}/fields/${fieldId}`);
|
||||
},
|
||||
};
|
||||
|
||||
export const getFileUploadSettingByCode = endpoint<string, FileUploadSetting>(
|
||||
QUERY_KEYS.FILES.FILE_UPLOAD_SETTINGS,
|
||||
QUERY_KEYS.FILES.BY_CODE,
|
||||
(code: any) =>
|
||||
client
|
||||
.get<
|
||||
ApiResponse<FileUploadSetting>
|
||||
>(`${URL_CONSTANTS.FILES.FILE_UPLOAD_SETTINGS_BY_CODE}/${code}`)
|
||||
.then((res: any) => res.data.data),
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { api as client } from "@/auth/http";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
import type {
|
||||
ApproveRatePayload,
|
||||
RuleEngineListMeta,
|
||||
RuleEngineListResult,
|
||||
RuleEngineRecord,
|
||||
@@ -143,11 +142,8 @@ export const ruleEngineService = {
|
||||
return normalizeEntity<T>(response.data);
|
||||
},
|
||||
|
||||
approveRate: async <T extends RuleEngineRecord>(
|
||||
id: string,
|
||||
payload: ApproveRatePayload,
|
||||
): Promise<T> => {
|
||||
const response = await client.post(URL_CONSTANTS.RULE_ENGINE.RATE_APPROVE(id), payload);
|
||||
approveRate: async <T extends RuleEngineRecord>(id: string): Promise<T> => {
|
||||
const response = await client.post(URL_CONSTANTS.RULE_ENGINE.RATE_APPROVE(id));
|
||||
return normalizeEntity<T>(response.data);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user