inspection plans and vehicle types

This commit is contained in:
Julian Krauser 2025-04-11 14:14:11 +02:00
parent 00fad29b25
commit e25d91802c
32 changed files with 1384 additions and 172 deletions

View file

@ -0,0 +1,110 @@
import { defineStore } from "pinia";
import type {
InspectionPlanViewModel,
CreateInspectionPlanViewModel,
UpdateInspectionPlanViewModel,
} from "@/viewmodels/admin/unit/inspectionPlan/inspectionPlan.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { inspectionPlanDemoData } from "@/demodata/inspectionPlan";
export const useInspectionPlanStore = defineStore("inspectionPlan", {
state: () => {
return {
inspectionPlans: [] as Array<InspectionPlanViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
activeInspectionPlan: null as string | null,
activeInspectionPlanObj: null as InspectionPlanViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchInspectionPlans(offset = 0, count = 25, search = "", clear = false) {
this.inspectionPlans = inspectionPlanDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.inspectionPlans.length;
this.loading = "fetched";
return;
if (clear) this.inspectionPlans = [];
this.loading = "loading";
http
.get(`/admin/inspectionPlan?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.inspectionPlans
.filter((elem: InspectionPlanViewModel) => this.inspectionPlans.findIndex((m) => m.id == elem.id) == -1)
.map((elem: InspectionPlanViewModel, index: number): InspectionPlanViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
})
.forEach((elem: InspectionPlanViewModel & { tab_pos: number }) => {
this.inspectionPlans.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async getAllInspectionPlans(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/inspectionPlan?noLimit=true`).then((res) => {
return { ...res, data: res.data.inspectionPlans };
});
},
async getInspectionPlansByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
return await http
.post(`/admin/inspectionPlan/ids`, {
ids,
})
.then((res) => {
return { ...res, data: res.data.inspectionPlans };
});
},
async searchInspectionPlans(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/inspectionPlan?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.inspectionPlans };
});
},
fetchInspectionPlanByActiveId() {
this.activeInspectionPlanObj = inspectionPlanDemoData.find(
(e) => e.id == this.activeInspectionPlan
) as InspectionPlanViewModel;
this.loading = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/inspectionPlan/${this.activeInspectionPlan}`)
.then((res) => {
this.activeInspectionPlanObj = res.data;
this.loadingActive = "fetched";
})
.catch((err) => {
this.loadingActive = "failed";
});
},
fetchInspectionPlanById(id: string) {
return http.get(`/admin/inspectionPlan/${id}`);
},
async createInspectionPlan(inspectionPlan: CreateInspectionPlanViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/inspectionPlan`, {
// TODO: data
});
this.fetchInspectionPlans();
return result;
},
async updateActiveInspectionPlan(inspectionPlan: UpdateInspectionPlanViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/inspectionPlan/${inspectionPlan.id}`, {
// TODO: data
});
this.fetchInspectionPlans();
return result;
},
async deleteInspectionPlan(inspectionPlan: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/inspectionPlan/${inspectionPlan}`);
this.fetchInspectionPlans();
return result;
},
},
});

View file

@ -0,0 +1,101 @@
import { defineStore } from "pinia";
import type {
VehicleTypeViewModel,
CreateVehicleTypeViewModel,
UpdateVehicleTypeViewModel,
} from "@/viewmodels/admin/unit/vehicleType/vehicleType.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { vehicleTypeDemoData } from "../../../../demodata/vehicleType";
export const useVehicleTypeStore = defineStore("vehicleType", {
state: () => {
return {
vehicleTypes: [] as Array<VehicleTypeViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
activeVehicleType: null as string | null,
activeVehicleTypeObj: null as VehicleTypeViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchVehicleTypes(offset = 0, count = 25, search = "", clear = false) {
this.vehicleTypes = vehicleTypeDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.vehicleTypes.length;
this.loading = "fetched";
return;
if (clear) this.vehicleTypes = [];
this.loading = "loading";
http
.get(`/admin/vehicleType?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.vehicles
.filter((elem: VehicleTypeViewModel) => this.vehicleTypes.findIndex((m) => m.id == elem.id) == -1)
.map((elem: VehicleTypeViewModel, index: number): VehicleTypeViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
})
.forEach((elem: VehicleTypeViewModel & { tab_pos: number }) => {
this.vehicleTypes.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async getAllVehicleTypes(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/vehicleType?noLimit=true`).then((res) => {
return { ...res, data: res.data.vehicles };
});
},
async searchVehicleTypes(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/vehicleType?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.vehicles };
});
},
fetchVehicleTypeByActiveId() {
this.activeVehicleTypeObj = vehicleTypeDemoData.find(
(e) => e.id == this.activeVehicleType
) as VehicleTypeViewModel;
this.loadingActive = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/vehicleType/${this.activeVehicleType}`)
.then((res) => {
this.activeVehicleTypeObj = res.data;
this.loadingActive = "fetched";
})
.catch((err) => {
this.loadingActive = "failed";
});
},
fetchVehicleTypeById(id: string) {
return http.get(`/admin/vehicleType/${id}`);
},
async createVehicleType(vehicleType: CreateVehicleTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/vehicleType`, {
// TODO: data
});
this.fetchVehicleTypes();
return result;
},
async updateActiveVehicleType(vehicleType: UpdateVehicleTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/vehicleType/${vehicleType.id}`, {
// TODO: data
});
this.fetchVehicleTypes();
return result;
},
async deleteVehicleType(vehicleType: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/vehicleType/${vehicleType}`);
this.fetchVehicleTypes();
return result;
},
},
});