mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 20:40:55 +00:00
Empties already sitting in an EDR yard but never entered in the system had to be typed one at a time. Adds a bulk path: parse the sheet in the browser (all-or-nothing, row-numbered errors), preview it, then POST one batch. The server rejects the batch if any container already has a non-COMPLETED return, so re-uploading the same sheet cannot duplicate boxes. No interchange notification fires — these are historical rows, not a live handover. Company is an Autocomplete over registered customers that also accepts a typed name, since a backfilled box may belong to a company that is not a customer yet. Exact name match sets customer_id; the name always lands in the new empty_container_returns.company_name. Also fixes the single Record Return modal, which collected Yard and Zone and then dropped them before the API call, and did not invalidate the returns list after a standalone return.
165 lines
5.2 KiB
TypeScript
165 lines
5.2 KiB
TypeScript
import { api as client } from '../auth/http';
|
|
import { URL_CONSTANTS } from '@/constants/URLS';
|
|
import { unwrap } from '@/utils/endpoint';
|
|
import type {
|
|
AssignCustomsRiskPayload,
|
|
CreateDjiboutiIncidentPayload,
|
|
CreateEmptyContainerReturnPayload,
|
|
LoadEmptyContainersOnTrainPayload,
|
|
DjiboutiIncident,
|
|
EmptyContainerReturn,
|
|
ImportCustomsFinalization,
|
|
ImportOperationActionPayload,
|
|
RecordDeclarationPayload,
|
|
UpdateEmptyContainerReturnStatusPayload,
|
|
UploadImportCustomsDocumentPayload,
|
|
} from '@/types/importOperations';
|
|
|
|
export const importOperationsService = {
|
|
listIncidents: async (bookingId?: string): Promise<DjiboutiIncident[]> => {
|
|
const response = await client.get<DjiboutiIncident[]>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.DJIBOUTI_INCIDENTS,
|
|
{ params: { bookingId } },
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
createIncident: async (
|
|
payload: CreateDjiboutiIncidentPayload,
|
|
): Promise<DjiboutiIncident> => {
|
|
const response = await client.post<DjiboutiIncident>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.DJIBOUTI_INCIDENTS,
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
getCustoms: async (bookingId: string): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.get<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS(bookingId),
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
uploadCustomsDocument: async (
|
|
bookingId: string,
|
|
payload: UploadImportCustomsDocumentPayload,
|
|
): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.post<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_DOCUMENTS(bookingId),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
recordDeclaration: async (
|
|
bookingId: string,
|
|
payload: RecordDeclarationPayload,
|
|
): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.post<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_DECLARATION(bookingId),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
notifyDutiesTaxes: async (
|
|
bookingId: string,
|
|
payload: ImportOperationActionPayload = {},
|
|
): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.post<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_NOTIFY_DUTIES_TAXES(bookingId),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
markDutiesTaxesPaid: async (
|
|
bookingId: string,
|
|
payload: ImportOperationActionPayload = {},
|
|
): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.post<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_DUTIES_TAXES_PAID(bookingId),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
assignRisk: async (
|
|
bookingId: string,
|
|
payload: AssignCustomsRiskPayload,
|
|
): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.post<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_RISK(bookingId),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
markReleasePermitted: async (
|
|
bookingId: string,
|
|
payload: ImportOperationActionPayload = {},
|
|
): Promise<ImportCustomsFinalization> => {
|
|
const response = await client.post<ImportCustomsFinalization>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_RELEASE_PERMITTED(bookingId),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
listEmptyReturns: async (): Promise<EmptyContainerReturn[]> => {
|
|
const response = await client.get<EmptyContainerReturn[]>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
createEmptyReturn: async (
|
|
payload: CreateEmptyContainerReturnPayload,
|
|
): Promise<EmptyContainerReturn> => {
|
|
const response = await client.post<EmptyContainerReturn>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS,
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
/** Backfill empties already in the yard. All-or-nothing on the server. */
|
|
bulkCreateEmptyReturns: async (
|
|
returns: CreateEmptyContainerReturnPayload[],
|
|
): Promise<EmptyContainerReturn[]> => {
|
|
const response = await client.post<EmptyContainerReturn[]>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS_BULK,
|
|
{ returns },
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
loadEmptyContainersOnTrain: async (
|
|
payload: LoadEmptyContainersOnTrainPayload,
|
|
): Promise<EmptyContainerReturn[]> => {
|
|
const response = await client.post<EmptyContainerReturn[]>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS_LOAD_ON_TRAIN,
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
updateEmptyReturnStatus: async (
|
|
id: string,
|
|
payload: UpdateEmptyContainerReturnStatusPayload,
|
|
): Promise<EmptyContainerReturn> => {
|
|
const response = await client.post<EmptyContainerReturn>(
|
|
URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURN_STATUS(id),
|
|
payload,
|
|
);
|
|
return unwrap(response.data);
|
|
},
|
|
|
|
/** Equipment interchange receipt — the doc handed to the customer at handover. */
|
|
downloadEquipmentInterchangeDocument: (id: string) =>
|
|
client.get<Blob>(URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURN_DOCUMENT(id), {
|
|
responseType: 'blob',
|
|
}),
|
|
};
|