inspection finish and print

This commit is contained in:
Julian Krauser 2025-07-11 14:02:39 +02:00
parent d96c73d5b1
commit 5d26885da3
14 changed files with 367 additions and 29 deletions

View file

@ -3,6 +3,7 @@ import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
CreateInspectionViewModel,
CreateOrUpdateInspectionPointResultCommand,
InspectionNextViewModel,
InspectionViewModel,
MinifiedInspectionViewModel,
@ -89,6 +90,11 @@ export const useInspectionStore = defineStore("inspection", {
fetchInspectionById(id: string) {
return http.get(`/admin/inspection/${id}`);
},
fetchInspectionPrintoutById() {
return http.get(`/admin/inspection/${this.activeInspectionObj?.id}/printout`, {
responseType: "blob",
});
},
async createInspection(inspection: CreateInspectionViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/inspection`, {
assigned: inspection.assigned,
@ -100,17 +106,41 @@ export const useInspectionStore = defineStore("inspection", {
return result;
},
async updateActiveInspection(inspection: UpdateInspectionViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/inspection/${inspection.id}`, {
const result = await http.patch(`/admin/inspection/${this.activeInspection}`, {
nextInspection: inspection.nextInspection,
context: inspection.context,
});
this.fetchInspectionByActiveId();
return result;
},
async deleteInspection(inspection: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/inspection/${inspection}`);
async updateActiveInspectionResults(
results: Array<CreateOrUpdateInspectionPointResultCommand>,
files: { [key: string]: File | null }
): Promise<AxiosResponse<any, any>> {
const formData = new FormData();
formData.append("results", JSON.stringify(results));
Object.entries(files).forEach(([key, file]) => {
if (file) {
const extension = file.name.split(".").pop() || "";
formData.append(`files`, new File([file], `${key}.${extension}`, { type: file.type }));
}
});
const result = await http.patch(`/admin/inspection/${this.activeInspection}/results`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
this.fetchInspectionByActiveId();
return result;
},
async finishActiveInspection(): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/inspection/${this.activeInspection}/finish`);
this.fetchInspectionByActiveId();
return result;
},
async deleteInspection(inspection: string): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/inspection/${inspection}`);
return result;
},
},
});