2026-03-30 07:53:42 -05:00
|
|
|
import { workOrderApi } from "../../services/api";
|
2026-04-16 18:22:34 -04:00
|
|
|
import { post } from "../../apiUtil";
|
|
|
|
|
import { API_URL } from "../../constants";
|
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 18:09:57 -04:00
|
|
|
auditLog: wo.auditLog ?? [],
|
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 {
|
2026-04-16 18:12:44 -04:00
|
|
|
return await workOrderApi.update(workOrder.id, {
|
|
|
|
|
Id: workOrder.id,
|
|
|
|
|
WorkerOrderNumber: workOrder.workOrderNumber,
|
|
|
|
|
WorkerOrderTitle: workOrder.title,
|
|
|
|
|
Description: workOrder.description,
|
|
|
|
|
PO: workOrder.po,
|
|
|
|
|
TT: workOrder.tt,
|
|
|
|
|
AssignTo: workOrder.assignedTo || null,
|
|
|
|
|
DueDate: workOrder.dueDate || null,
|
|
|
|
|
Priority: workOrder.priority || null,
|
|
|
|
|
Status: workOrder.status,
|
|
|
|
|
LocationId: workOrder.locationId ? parseInt(workOrder.locationId) : null,
|
|
|
|
|
});
|
2026-03-30 07:53:42 -05:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error updating work order:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-01-20 15:05:00 -06:00
|
|
|
};
|
|
|
|
|
|
2026-04-16 18:22:34 -04:00
|
|
|
export const addComment = async (workOrderId, text, commentType = "internal") => {
|
|
|
|
|
return post(`${API_URL}/WorkOrder/AddCommentJson`, {
|
|
|
|
|
WorkorderId: workOrderId,
|
|
|
|
|
Text: text,
|
|
|
|
|
CommentType: commentType,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
};
|