56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
|
import { defineStore } from "pinia";
|
||
|
import { http } from "@/serverCom";
|
||
|
import type { AxiosResponse } from "axios";
|
||
|
import { inspectionDemoData } from "@/demodata/inspectionPlan";
|
||
|
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";
|
||
|
this.activeInspectionObj = inspectionDemoData.find((e) => e.id == this.activeInspection) as InspectionViewModel;
|
||
|
this.loadingActive = "fetched";
|
||
|
return;
|
||
|
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`, {
|
||
|
// TODO: data
|
||
|
});
|
||
|
this.fetchInspectionByActiveId();
|
||
|
return result;
|
||
|
},
|
||
|
async updateActiveInspection(inspection: any): Promise<AxiosResponse<any, any>> {
|
||
|
const result = await http.patch(`/admin/inspection/${inspection.id}`, {
|
||
|
// TODO: data
|
||
|
});
|
||
|
this.fetchInspectionByActiveId();
|
||
|
return result;
|
||
|
},
|
||
|
async deleteInspection(inspection: number): Promise<AxiosResponse<any, any>> {
|
||
|
const result = await http.delete(`/admin/inspection/${inspection}`);
|
||
|
this.fetchInspectionByActiveId();
|
||
|
return result;
|
||
|
},
|
||
|
},
|
||
|
});
|