save inspectionPoints

This commit is contained in:
Julian Krauser 2025-07-09 16:01:15 +02:00
parent eb4d338583
commit 23bdde5fc2
13 changed files with 407 additions and 72 deletions

View file

@ -53,6 +53,25 @@ export const useInspectionPlanStore = defineStore("inspectionPlan", {
return { ...res, data: res.data.inspectionPlans };
});
},
async getAllInspectionPlansWithRelated(
related: "vehicle" | "equipment" | "wearable",
relatedId: string
): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/inspectionPlan/${related}/${relatedId}?noLimit=true`).then((res) => {
return { ...res, data: res.data.inspectionPlans };
});
},
async searchInspectionPlansWithRelated(
related: "vehicle" | "equipment" | "wearable",
relatedId: string,
search: string
): Promise<AxiosResponse<any, any>> {
return await http
.get(`/admin/inspectionPlan/${related}/${relatedId}?search=${search}&noLimit=true`)
.then((res) => {
return { ...res, data: res.data.inspectionPlans };
});
},
fetchInspectionPlanByActiveId() {
this.loadingActive = "loading";
http

View file

@ -0,0 +1,37 @@
import { defineStore } from "pinia";
import type { InspectionPointViewModel } from "@/viewmodels/admin/unit/inspection/inspectionPlan.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { useInspectionPlanStore } from "./inspectionPlan";
export const useInspectionPointStore = defineStore("inspectionPoint", {
state: () => {
return {
inspectionPoints: [] as Array<InspectionPointViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchInspectionPoints() {
const inspectionPlanId = useInspectionPlanStore().activeInspectionPlan;
this.loading = "loading";
http
.get(`/admin/inspectionPlan/${inspectionPlanId}/points`)
.then((result) => {
this.inspectionPoints = result.data;
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async updateActiveInspectionPoints(
inspectionPoints: Array<InspectionPointViewModel>
): Promise<AxiosResponse<any, any>> {
const inspectionPlanId = useInspectionPlanStore().activeInspectionPlan;
const result = await http.patch(`/admin/inspectionPlan/${inspectionPlanId}/points`, inspectionPoints);
this.fetchInspectionPoints();
return result;
},
},
});