2025-05-16 10:27:08 +02:00
|
|
|
import { defineStore } from "pinia";
|
|
|
|
import { http } from "@/serverCom";
|
|
|
|
import type { AxiosResponse } from "axios";
|
|
|
|
import type { InspectionViewModel } from "@/viewmodels/admin/unit/inspection/inspection.models";
|
|
|
|
|
|
|
|
export const useInspectionStore = defineStore("inspection", {
|
|
|
|
state: () => {
|
|
|
|
return {
|
|
|
|
activeInspection: null as string | null,
|
|
|
|
activeInspectionObj: null as InspectionViewModel | null,
|
|
|
|
loadingActive: "loading" as "loading" | "fetched" | "failed",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
fetchInspectionByActiveId() {
|
|
|
|
this.loadingActive = "loading";
|
|
|
|
http
|
|
|
|
.get(`/admin/inspection/${this.activeInspection}`)
|
|
|
|
.then((res) => {
|
|
|
|
this.activeInspectionObj = res.data;
|
|
|
|
this.loadingActive = "fetched";
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.loadingActive = "failed";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchInspectionById(id: string) {
|
|
|
|
return http.get(`/admin/inspection/${id}`);
|
|
|
|
},
|
|
|
|
async createInspection(inspection: any): Promise<AxiosResponse<any, any>> {
|
|
|
|
const result = await http.post(`/admin/inspection`, {
|
2025-06-04 14:30:41 +02:00
|
|
|
context: "",
|
|
|
|
inspectionPlanId: "",
|
|
|
|
relatedId: "",
|
|
|
|
assigned: "equipment|vehicle",
|
2025-05-16 10:27:08 +02:00
|
|
|
});
|
|
|
|
this.fetchInspectionByActiveId();
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
async updateActiveInspection(inspection: any): Promise<AxiosResponse<any, any>> {
|
|
|
|
const result = await http.patch(`/admin/inspection/${inspection.id}`, {
|
2025-06-04 14:30:41 +02:00
|
|
|
context: "",
|
2025-05-16 10:27:08 +02:00
|
|
|
});
|
|
|
|
this.fetchInspectionByActiveId();
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
async deleteInspection(inspection: number): Promise<AxiosResponse<any, any>> {
|
|
|
|
const result = await http.delete(`/admin/inspection/${inspection}`);
|
|
|
|
this.fetchInspectionByActiveId();
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|