mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 06:59:01 +00:00
pm schedule fix
This commit is contained in:
parent
65bf95b20c
commit
1632f1e656
1 changed files with 26 additions and 52 deletions
|
|
@ -1,67 +1,41 @@
|
||||||
// Mock PM schedules data
|
import { get, post } from "../../apiUtil";
|
||||||
const mockPMSchedules = [
|
import { API_URL } from "../../constants";
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
asset: "HVAC-001",
|
|
||||||
assetName: "Building A HVAC System",
|
|
||||||
frequency: "Quarterly",
|
|
||||||
lastServiceDate: "2024-01-15",
|
|
||||||
nextServiceDate: "2024-04-15",
|
|
||||||
status: "Active",
|
|
||||||
assignedTo: "John Anderson",
|
|
||||||
notes: "Quarterly maintenance check",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
asset: "ELEC-002",
|
|
||||||
assetName: "Main Electrical Panel",
|
|
||||||
frequency: "Annual",
|
|
||||||
lastServiceDate: "2023-12-01",
|
|
||||||
nextServiceDate: "2024-12-01",
|
|
||||||
status: "Active",
|
|
||||||
assignedTo: "Sarah Martinez",
|
|
||||||
notes: "Annual electrical inspection",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
asset: "PLUMB-001",
|
|
||||||
assetName: "Building B Plumbing System",
|
|
||||||
frequency: "Semi-Annual",
|
|
||||||
lastServiceDate: "2024-01-10",
|
|
||||||
nextServiceDate: "2024-07-10",
|
|
||||||
status: "Active",
|
|
||||||
assignedTo: "Mike Johnson",
|
|
||||||
notes: "Bi-annual plumbing inspection",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const getPMSchedules = async () => {
|
export const getPMSchedules = async () => {
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
const response = await get(`${API_URL}/PMSchedule/GetList`);
|
||||||
return [...mockPMSchedules];
|
return Array.isArray(response) ? response : (response?.value || response?.data || response?.Data || []);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPMScheduleById = async (id) => {
|
export const getPMScheduleById = async (id) => {
|
||||||
await new Promise(resolve => setTimeout(resolve, 200));
|
return get(`${API_URL}/PMSchedule/GetById?id=${id}`);
|
||||||
return mockPMSchedules.find(p => p.id === parseInt(id));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addPMSchedule = async (pmSchedule) => {
|
export const addPMSchedule = async (pmSchedule) => {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
const payload = {
|
||||||
const newPMSchedule = { id: mockPMSchedules.length + 1, ...pmSchedule };
|
Id: 0,
|
||||||
mockPMSchedules.push(newPMSchedule);
|
Name: pmSchedule.assetName || pmSchedule.name,
|
||||||
return newPMSchedule;
|
Frequency: pmSchedule.frequency,
|
||||||
|
StartDate: pmSchedule.nextServiceDate || pmSchedule.startDate,
|
||||||
|
IsActive: pmSchedule.status === "Active" || pmSchedule.isActive !== false,
|
||||||
|
AssetId: pmSchedule.assetId || null,
|
||||||
|
LocationId: pmSchedule.locationId || null
|
||||||
|
};
|
||||||
|
return post(`${API_URL}/PMSchedule/Save`, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editPMSchedule = async (pmSchedule) => {
|
export const editPMSchedule = async (pmSchedule) => {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
const payload = {
|
||||||
const idx = mockPMSchedules.findIndex(p => p.id === pmSchedule.id);
|
Id: pmSchedule.id,
|
||||||
if (idx >= 0) mockPMSchedules[idx] = pmSchedule;
|
Name: pmSchedule.assetName || pmSchedule.name,
|
||||||
return pmSchedule;
|
Frequency: pmSchedule.frequency,
|
||||||
|
StartDate: pmSchedule.nextServiceDate || pmSchedule.startDate,
|
||||||
|
IsActive: pmSchedule.status === "Active" || pmSchedule.isActive !== false,
|
||||||
|
AssetId: pmSchedule.assetId || null,
|
||||||
|
LocationId: pmSchedule.locationId || null
|
||||||
|
};
|
||||||
|
return post(`${API_URL}/PMSchedule/Save`, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deletePMSchedule = async (id) => {
|
export const deletePMSchedule = async (id) => {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
return post(`${API_URL}/PMSchedule/Delete?id=${id}`);
|
||||||
const idx = mockPMSchedules.findIndex(p => p.id === id);
|
|
||||||
if (idx >= 0) mockPMSchedules.splice(idx, 1);
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue