2026-03-30 07:53:42 -05:00
|
|
|
import { workOrderApi } from "../../services/api";
|
2026-01-20 15:05:00 -06:00
|
|
|
|
2026-03-30 07:53:42 -05:00
|
|
|
export const getWorkOrders = async (params = {}) => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await workOrderApi.getAll(params);
|
|
|
|
|
const workOrders = response.data || response;
|
|
|
|
|
return Array.isArray(workOrders) ? workOrders : [];
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching work orders:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-01-20 15:05:00 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getWorkOrderById = async (id) => {
|
2026-03-30 07:53:42 -05:00
|
|
|
try {
|
2026-04-16 17:37:21 -04:00
|
|
|
const wo = await workOrderApi.getById(id);
|
|
|
|
|
return {
|
|
|
|
|
id: wo.id,
|
|
|
|
|
workOrderNumber: wo.workerOrderNumber ?? wo.workOrderNumber ?? "",
|
|
|
|
|
title: wo.title ?? wo.workerOrderTitle ?? "",
|
|
|
|
|
location: wo.location ?? "",
|
2026-04-16 17:45:19 -04:00
|
|
|
locationId: wo.locationId != null ? String(wo.locationId) : "",
|
2026-04-16 17:37:21 -04:00
|
|
|
assignedTo: wo.assignee ?? wo.assignedTo ?? "",
|
|
|
|
|
dueDate: wo.dueDate ? wo.dueDate.split("T")[0] : "",
|
|
|
|
|
createdDate: wo.createdDate ? wo.createdDate.split("T")[0] : "",
|
2026-04-16 17:54:21 -04:00
|
|
|
createdDateFull: wo.createdDate ?? "",
|
2026-04-16 17:37:21 -04:00
|
|
|
description: wo.description ?? "",
|
|
|
|
|
priority: wo.priority ?? "",
|
|
|
|
|
status: wo.status ?? "Open",
|
|
|
|
|
po: wo.po ?? "",
|
|
|
|
|
tt: wo.tt ?? "",
|
2026-04-16 17:41:11 -04:00
|
|
|
comments: wo.comments ?? [],
|
2026-04-16 17:37:21 -04:00
|
|
|
};
|
2026-03-30 07:53:42 -05:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching work order:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-01-20 15:05:00 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const addWorkOrder = async (workOrder) => {
|
2026-03-30 07:53:42 -05:00
|
|
|
try {
|
|
|
|
|
return await workOrderApi.create(workOrder);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error creating work order:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-01-20 15:05:00 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const editWorkOrder = async (workOrder) => {
|
2026-03-30 07:53:42 -05:00
|
|
|
try {
|
|
|
|
|
return await workOrderApi.update(workOrder.id, workOrder);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error updating work order:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-01-20 15:05:00 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const deleteWorkOrder = async (id) => {
|
2026-03-30 07:53:42 -05:00
|
|
|
try {
|
|
|
|
|
await workOrderApi.delete(id);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error deleting work order:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-01-20 15:05:00 -06:00
|
|
|
};
|