mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 04:12:09 +00:00
fix(work-orders): align routes, delete body, and create payload
This commit is contained in:
parent
b4873cf1f8
commit
e4a1435f3c
3 changed files with 53 additions and 31 deletions
|
|
@ -99,7 +99,7 @@ export const workOrdersApi = {
|
|||
},
|
||||
|
||||
getById: async (id: string | number): Promise<WorkOrderDetail> => {
|
||||
const data = await apiGet<unknown>(API_PATHS.workOrder.getById, { searchParams: { id } });
|
||||
const data = await apiGet<unknown>(`${API_PATHS.workOrder.getById}/${id}`);
|
||||
return mapWorkOrderDetail(handleApiResponse(data));
|
||||
},
|
||||
|
||||
|
|
@ -121,7 +121,9 @@ export const workOrdersApi = {
|
|||
},
|
||||
|
||||
delete: async (id: string | number): Promise<void> => {
|
||||
await apiDelete<unknown>(API_PATHS.workOrder.deleteWorkorder, { searchParams: { id } });
|
||||
await apiDelete(API_PATHS.workOrder.deleteWorkorder, {
|
||||
json: { Id: Number(id) },
|
||||
});
|
||||
},
|
||||
|
||||
addComment: async (
|
||||
|
|
@ -156,9 +158,29 @@ export const workOrdersApi = {
|
|||
},
|
||||
|
||||
fetchEmployeesDropdown: async (): Promise<EmployeeOption[]> => {
|
||||
const data = await apiGet<unknown>(API_PATHS.employee.dropdown);
|
||||
const items = handleApiResponse<unknown[]>(data);
|
||||
return Array.isArray(items) ? mapEmployeeOptions(items) : [];
|
||||
try {
|
||||
const data = await apiGet<unknown>(API_PATHS.employee.dropdown);
|
||||
const items = handleApiResponse<unknown[]>(data);
|
||||
return Array.isArray(items) ? mapEmployeeOptions(items) : [];
|
||||
} catch {
|
||||
const data = await apiGet<unknown>(API_PATHS.employee.getList, {
|
||||
searchParams: { page: 1, pageSize: 1000 },
|
||||
});
|
||||
const paginated = handlePaginatedResponse<unknown>(data);
|
||||
const items = paginated.items.map((item) => {
|
||||
const record = (typeof item === "object" && item !== null ? item : {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const firstName = String(record.firstName ?? record.FirstName ?? "");
|
||||
const lastName = String(record.lastName ?? record.LastName ?? "");
|
||||
return {
|
||||
id: record.id ?? record.Id,
|
||||
name: `${firstName} ${lastName}`.trim(),
|
||||
};
|
||||
});
|
||||
return mapEmployeeOptions(items);
|
||||
}
|
||||
},
|
||||
|
||||
fetchVendorsDropdown: async (trade?: string, siteZip?: string): Promise<VendorDropdownItem[]> => {
|
||||
|
|
|
|||
|
|
@ -208,24 +208,24 @@ export function mapWorkOrderFormToCreatePayload(
|
|||
values: WorkOrderFormValues,
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
workOrderNumber: values.workOrderNumber,
|
||||
title: values.title,
|
||||
locationId: values.locationId ? parseInt(values.locationId, 10) : null,
|
||||
priority: values.priority || null,
|
||||
status: values.status,
|
||||
createdDate: values.createdDate || null,
|
||||
dueDate: values.dueDate || null,
|
||||
scheduledDate: values.scheduledDate || null,
|
||||
completedDate: values.completedDate || null,
|
||||
assignedTo: values.assignedTo || null,
|
||||
description: values.description,
|
||||
po: values.po || null,
|
||||
tt: values.tt || null,
|
||||
problem: values.problem || null,
|
||||
trade: values.trade || null,
|
||||
subTrade: values.subTrade || null,
|
||||
vendorNTE: values.vendorNTE ? parseFloat(values.vendorNTE) : null,
|
||||
source: values.source || null,
|
||||
WorkerOrderNumber: values.workOrderNumber,
|
||||
WorkerOrderTitle: values.title,
|
||||
LocationId: values.locationId ? parseInt(values.locationId, 10) : null,
|
||||
Priority: values.priority || null,
|
||||
Status: values.status,
|
||||
CreatedDate: values.createdDate || null,
|
||||
DueDate: values.dueDate || null,
|
||||
ScheduledDate: values.scheduledDate || null,
|
||||
CompletedDate: values.completedDate || null,
|
||||
AssignTo: values.assignedTo || null,
|
||||
Description: values.description,
|
||||
PO: values.po || null,
|
||||
TT: values.tt || null,
|
||||
Problem: values.problem || null,
|
||||
Trade: values.trade || null,
|
||||
SubTrade: values.subTrade || null,
|
||||
VendorNTE: values.vendorNTE ? parseFloat(values.vendorNTE) : null,
|
||||
Source: values.source || null,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ describe("mapWorkOrderFormToCreatePayload", () => {
|
|||
};
|
||||
|
||||
expect(mapWorkOrderFormToCreatePayload(values)).toMatchObject({
|
||||
workOrderNumber: "CUST-001",
|
||||
title: "Replace filter",
|
||||
locationId: 42,
|
||||
priority: "Sev 1",
|
||||
status: "Open",
|
||||
createdDate: "2026-01-15",
|
||||
assignedTo: "Jane Doe",
|
||||
description: "HVAC filter replacement",
|
||||
WorkerOrderNumber: "CUST-001",
|
||||
WorkerOrderTitle: "Replace filter",
|
||||
LocationId: 42,
|
||||
Priority: "Sev 1",
|
||||
Status: "Open",
|
||||
CreatedDate: "2026-01-15",
|
||||
AssignTo: "Jane Doe",
|
||||
Description: "HVAC filter replacement",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue