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> { const result = await http.post(`/admin/inspection`, { context: "", inspectionPlanId: "", relatedId: "", assigned: "equipment|vehicle", }); this.fetchInspectionByActiveId(); return result; }, async updateActiveInspection(inspection: any): Promise> { const result = await http.patch(`/admin/inspection/${inspection.id}`, { context: "", }); this.fetchInspectionByActiveId(); return result; }, async deleteInspection(inspection: number): Promise> { const result = await http.delete(`/admin/inspection/${inspection}`); this.fetchInspectionByActiveId(); return result; }, }, });