- Backend: CRUD revízií, schedule endpoint (agregovaný plán), skip revízia, stats - Shared utility revisionSchedule.ts - centralizovaná logika výpočtu cyklov - Equipment detail s revíznym plánom, históriou a prílohami - Frontend: RevisionsList s tabmi (nadchádzajúce/po termíne/vykonané/preskočené) - Pozičné labeling cyklov (eliminuje drift 4×90≠365) - EquipmentRevisionSchedule model (many-to-many typy revízií) - Aktualizovaná dokumentácia HELPDESK_INIT_V2.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
106 lines
2.9 KiB
TypeScript
106 lines
2.9 KiB
TypeScript
import { get, getPaginated, post, put, del } from './api';
|
|
import type { Equipment, Revision } from '@/types';
|
|
|
|
export interface EquipmentFilters {
|
|
search?: string;
|
|
customerId?: string;
|
|
typeId?: string;
|
|
active?: boolean;
|
|
page?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
export interface CreateEquipmentData {
|
|
name: string;
|
|
typeId: string;
|
|
brand?: string;
|
|
model?: string;
|
|
customerId?: string;
|
|
address: string;
|
|
location?: string;
|
|
partNumber?: string;
|
|
serialNumber?: string;
|
|
installDate?: string;
|
|
revisionCycleStart?: string;
|
|
warrantyEnd?: string;
|
|
warrantyStatus?: string;
|
|
description?: string;
|
|
notes?: string;
|
|
active?: boolean;
|
|
revisionTypeIds?: string[];
|
|
tempId?: string; // For pending file uploads
|
|
}
|
|
|
|
export interface EquipmentScheduleItem {
|
|
revisionType: { id: string; name: string; color?: string; intervalDays: number };
|
|
lastPerformed: string | null;
|
|
nextDueDate: string | null;
|
|
upcomingCycles: string[];
|
|
}
|
|
|
|
export interface EquipmentSchedule {
|
|
cycleAnchor: string;
|
|
schedules: EquipmentScheduleItem[];
|
|
upcomingDates: Array<{
|
|
date: string;
|
|
label: string;
|
|
revisionTypes: Array<{
|
|
id: string;
|
|
name: string;
|
|
color?: string;
|
|
intervalDays: number;
|
|
cycleNumber: number;
|
|
}>;
|
|
}>;
|
|
}
|
|
|
|
export type UpdateEquipmentData = Partial<CreateEquipmentData>;
|
|
|
|
export interface CreateRevisionData {
|
|
typeId: string;
|
|
performedDate: string;
|
|
nextDueDate?: string;
|
|
findings?: string;
|
|
result?: string;
|
|
notes?: string;
|
|
}
|
|
|
|
function buildQueryString(filters: EquipmentFilters): string {
|
|
const params = new URLSearchParams();
|
|
if (filters.search) params.append('search', filters.search);
|
|
if (filters.customerId) params.append('customerId', filters.customerId);
|
|
if (filters.typeId) params.append('typeId', filters.typeId);
|
|
if (filters.active !== undefined) params.append('active', String(filters.active));
|
|
if (filters.page) params.append('page', String(filters.page));
|
|
if (filters.limit) params.append('limit', String(filters.limit));
|
|
return params.toString();
|
|
}
|
|
|
|
export const equipmentApi = {
|
|
getAll: (filters: EquipmentFilters = {}) =>
|
|
getPaginated<Equipment>(`/equipment?${buildQueryString(filters)}`),
|
|
|
|
getById: (id: string) =>
|
|
get<Equipment>(`/equipment/${id}`),
|
|
|
|
create: (data: CreateEquipmentData) =>
|
|
post<Equipment>('/equipment', data),
|
|
|
|
update: (id: string, data: UpdateEquipmentData) =>
|
|
put<Equipment>(`/equipment/${id}`, data),
|
|
|
|
delete: (id: string) =>
|
|
del<void>(`/equipment/${id}`),
|
|
|
|
// Revisions
|
|
getRevisions: (equipmentId: string) =>
|
|
get<Revision[]>(`/equipment/${equipmentId}/revisions`),
|
|
|
|
createRevision: (equipmentId: string, data: CreateRevisionData) =>
|
|
post<Revision>(`/equipment/${equipmentId}/revisions`, data),
|
|
|
|
// Schedule
|
|
getSchedule: (equipmentId: string, days?: number) =>
|
|
get<EquipmentSchedule>(`/equipment/${equipmentId}/schedule${days ? `?days=${days}` : ''}`),
|
|
};
|