205 lines
5.8 KiB
TypeScript
205 lines
5.8 KiB
TypeScript
import { apiRequest } from './api';
|
|
|
|
export type InspectionReportStatus = 'WORKING' | 'OFFICIALIZED' | 'FROZEN' | 'CANCELLED';
|
|
export type InspectionReportFollowUpType =
|
|
| 'COMPANY_NOTE'
|
|
| 'COMPANY_DOCUMENT'
|
|
| 'INTERNAL_NOTE'
|
|
| 'VERIFICATION'
|
|
| 'OTHER';
|
|
|
|
export interface PageMetaF4 {
|
|
page: number;
|
|
pageSize: number;
|
|
total: number;
|
|
totalPages: number;
|
|
}
|
|
|
|
export interface InspectionReportQueryF4 {
|
|
page?: number;
|
|
pageSize?: number;
|
|
search?: string;
|
|
year?: number | string;
|
|
companyId?: string;
|
|
areaId?: string;
|
|
inspectorId?: string;
|
|
dateFrom?: string;
|
|
dateTo?: string;
|
|
}
|
|
|
|
export interface InspectionReportDetailF4 {
|
|
id: string;
|
|
visitId: string;
|
|
actId: string;
|
|
reportYear: number;
|
|
reportNumber: number;
|
|
code: string;
|
|
status: InspectionReportStatus;
|
|
executiveSummary: string | null;
|
|
reportDescription: string | null;
|
|
gedoIfIdentifier: string | null;
|
|
gedoOfficializedAt: string | null;
|
|
gedoPdfOriginalName: string | null;
|
|
gedoPdfSha256: string | null;
|
|
pdfStatus: 'PENDING' | 'READY' | 'FAILED';
|
|
wordStatus: 'PENDING' | 'READY' | 'FAILED';
|
|
wordGeneratedAt: string | null;
|
|
title: string;
|
|
actVersion: number;
|
|
actClosureSha256: string;
|
|
frozenSha256: string;
|
|
generatedAt: string;
|
|
generatedBy: { id: string; username: string; firstName: string; lastName: string };
|
|
act: {
|
|
id: string;
|
|
code: string;
|
|
title: string;
|
|
status: string;
|
|
occurredAt: string;
|
|
sealedAt: string | null;
|
|
urgency: string;
|
|
deadlineAt: string | null;
|
|
};
|
|
visit: { id: string; code: string; title: string; status: string };
|
|
companies: Array<{ id: string; code: string; name: string }>;
|
|
areas: Array<{ id: string; code: string; name: string }>;
|
|
findingCount: number;
|
|
}
|
|
|
|
export interface PendingInspectionReportF4 {
|
|
actId: string;
|
|
visitId: string;
|
|
actCode: string;
|
|
actTitle: string;
|
|
actYear: number;
|
|
occurredAt: string;
|
|
sealedAt: string;
|
|
closureSha256: string;
|
|
visitCode: string;
|
|
visitTitle: string;
|
|
companies: Array<{ id: string; code: string; name: string }>;
|
|
areas: Array<{ id: string; code: string; name: string }>;
|
|
findingCount: number;
|
|
}
|
|
|
|
export interface InspectionReportFollowUp {
|
|
id: string;
|
|
reportId: string;
|
|
type: InspectionReportFollowUpType;
|
|
externalReference: string | null;
|
|
occurredAt: string;
|
|
description: string | null;
|
|
originalName: string | null;
|
|
mimeType: string | null;
|
|
sizeBytes: number | null;
|
|
sha256: string | null;
|
|
createdBy: string | null;
|
|
createdAt: string;
|
|
}
|
|
|
|
export interface InspectionReportWorkflowView {
|
|
id: string;
|
|
actId: string;
|
|
visitId: string;
|
|
code: string;
|
|
status: InspectionReportStatus;
|
|
executiveSummary: string | null;
|
|
reportDescription: string | null;
|
|
gedoIfIdentifier: string | null;
|
|
gedoOfficializedAt: string | null;
|
|
act: {
|
|
code: string;
|
|
urgency: string;
|
|
deadlineDays: number | null;
|
|
deadlineDayType: 'BUSINESS' | 'CALENDAR' | null;
|
|
deadlineBasis: string | null;
|
|
deadlineBaseAt: string | null;
|
|
deadlineAt: string | null;
|
|
} | null;
|
|
followUps: InspectionReportFollowUp[];
|
|
}
|
|
|
|
function queryString(query: InspectionReportQueryF4): string {
|
|
const params = new URLSearchParams();
|
|
const add = (key: string, value: string | number | undefined) => {
|
|
if (value === undefined || value === '') return;
|
|
params.set(key, String(value));
|
|
};
|
|
add('page', query.page ?? 1);
|
|
add('pageSize', query.pageSize ?? 25);
|
|
add('search', query.search?.trim() || undefined);
|
|
add('year', query.year);
|
|
add('companyId', query.companyId);
|
|
add('areaId', query.areaId);
|
|
add('inspectorId', query.inspectorId);
|
|
add('dateFrom', query.dateFrom);
|
|
add('dateTo', query.dateTo);
|
|
return params.toString();
|
|
}
|
|
|
|
export function listInspectionReportsF4(query: InspectionReportQueryF4) {
|
|
return apiRequest<{ data: InspectionReportDetailF4[]; meta: PageMetaF4 }>(`/inspection-reports?${queryString(query)}`);
|
|
}
|
|
|
|
export function listPendingInspectionReportsF4(query: InspectionReportQueryF4) {
|
|
return apiRequest<{ data: PendingInspectionReportF4[]; meta: PageMetaF4 }>(`/inspection-reports/pending?${queryString(query)}`);
|
|
}
|
|
|
|
export function getInspectionReportF4(id: string) {
|
|
return apiRequest<InspectionReportDetailF4>(`/inspection-reports/${id}`);
|
|
}
|
|
|
|
export function listInspectionReportFollowUps(id: string) {
|
|
return apiRequest<InspectionReportFollowUp[]>(`/inspection-reports/${id}/follow-ups`);
|
|
}
|
|
|
|
export function updateInspectionReportNarrative(
|
|
id: string,
|
|
input: { executiveSummary?: string | null; description?: string | null },
|
|
) {
|
|
return apiRequest<InspectionReportWorkflowView>(`/inspection-reports/${id}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function officializeInspectionReport(
|
|
id: string,
|
|
input: { gedoIfIdentifier: string; gedoOfficializedAt: string; file: File },
|
|
) {
|
|
const body = new FormData();
|
|
body.set('gedoIfIdentifier', input.gedoIfIdentifier);
|
|
body.set('gedoOfficializedAt', input.gedoOfficializedAt);
|
|
body.set('file', input.file);
|
|
return apiRequest<InspectionReportWorkflowView>(`/inspection-reports/${id}/officialize`, {
|
|
method: 'POST',
|
|
body,
|
|
});
|
|
}
|
|
|
|
export function addInspectionReportFollowUp(
|
|
id: string,
|
|
input: {
|
|
type: InspectionReportFollowUpType;
|
|
occurredAt: string;
|
|
externalReference?: string | null;
|
|
description?: string | null;
|
|
file?: File | null;
|
|
},
|
|
) {
|
|
const body = new FormData();
|
|
body.set('type', input.type);
|
|
body.set('occurredAt', input.occurredAt);
|
|
if (input.externalReference?.trim()) body.set('externalReference', input.externalReference.trim());
|
|
if (input.description?.trim()) body.set('description', input.description.trim());
|
|
if (input.file) body.set('file', input.file);
|
|
return apiRequest<InspectionReportFollowUp[]>(`/inspection-reports/${id}/follow-ups`, {
|
|
method: 'POST',
|
|
body,
|
|
});
|
|
}
|
|
|
|
export function inspectionReportWordDownloadUrl(id: string) {
|
|
return `/api/v3/inspection-reports/${id}/word`;
|
|
}
|