connect to backend

This commit is contained in:
Julian Krauser 2025-06-04 14:30:41 +02:00
parent 6c8d57a7e5
commit ddeac1aa26
41 changed files with 221 additions and 291 deletions

View file

@ -17,12 +17,9 @@ export const useDamageReportStore = defineStore("damageReport", {
},
actions: {
fetchDamageReports(offset = 0, count = 25, search = "", clear = false) {
this.damageReports = damageReportDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.damageReports.length;
this.loading = "fetched";
return;
if (clear) this.damageReports = [];
this.loading = "loading";
//TODO enable fetch of done reports
http
.get(`/admin/damageReport?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
@ -66,13 +63,6 @@ export const useDamageReportStore = defineStore("damageReport", {
fetchDamageReportById(id: string) {
return http.get(`/admin/damageReport/${id}`);
},
async createDamageReport(damageReport: CreateDamageReportViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/damageReport`, {
// TODO: data
});
this.fetchDamageReports();
return result;
},
async updateDamageReport(damageReport: UpdateDamageReportViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/damageReport/${damageReport.id}`, {
// TODO: data
@ -80,10 +70,5 @@ export const useDamageReportStore = defineStore("damageReport", {
this.fetchDamageReports();
return result;
},
async deleteDamageReport(damageReport: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/damageReport/${damageReport}`);
this.fetchDamageReports();
return result;
},
},
});

View file

@ -14,17 +14,11 @@ export const useEquipmentDamageReportStore = defineStore("equipmentDamageReport"
actions: {
fetchDamageReportForEquipment(offset = 0, count = 25, search = "", clear = false) {
const equipmentId = useEquipmentStore().activeEquipment;
this.damageReports = damageReportDemoData
.filter((drdd) => drdd.relatedId == equipmentId)
.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.damageReports.length;
this.loading = "fetched";
return;
if (clear) this.damageReports = [];
this.loading = "loading";
http
.get(
`/admin/equipment/${equipmentId}/damageReport?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
`/admin/damagereport/equipment/${equipmentId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
)
.then((result) => {
this.totalCount = result.data.total;

View file

@ -6,7 +6,6 @@ import type {
} from "@/viewmodels/admin/unit/equipment/equipment.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { equipmentDemoData } from "@/demodata/equipment";
export const useEquipmentStore = defineStore("equipment", {
state: () => {
@ -21,10 +20,6 @@ export const useEquipmentStore = defineStore("equipment", {
},
actions: {
fetchEquipments(offset = 0, count = 25, search = "", clear = false) {
this.equipments = equipmentDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.equipments.length;
this.loading = "fetched";
return;
if (clear) this.equipments = [];
this.loading = "loading";
http
@ -68,9 +63,6 @@ export const useEquipmentStore = defineStore("equipment", {
});
},
fetchEquipmentByActiveId() {
this.activeEquipmentObj = equipmentDemoData.find((e) => e.id == this.activeEquipment) as EquipmentViewModel;
this.loadingActive = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/equipment/${this.activeEquipment}`)
@ -87,14 +79,22 @@ export const useEquipmentStore = defineStore("equipment", {
},
async createEquipment(equipment: CreateEquipmentViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/equipment`, {
// TODO: data
equipmentTypeId: equipment.equipmentTypeId,
name: equipment.name,
code: equipment.code,
location: equipment.location,
commissioned: equipment.commissioned,
});
this.fetchEquipments();
return result;
},
async updateActiveEquipment(equipment: UpdateEquipmentViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/equipment/${equipment.id}`, {
// TODO: data
name: equipment.name,
code: equipment.code,
location: equipment.location,
commissioned: equipment.commissioned,
decommissioned: equipment.decommissioned,
});
this.fetchEquipments();
return result;

View file

@ -1,7 +1,6 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { InspectionViewModel } from "@/viewmodels/admin/unit/inspection/inspection.models";
import { inspectionDemoData } from "@/demodata/inspectionPlan";
import { useEquipmentStore } from "./equipment";
export const useEquipmentInspectionStore = defineStore("equipmentInspection", {
@ -13,20 +12,12 @@ export const useEquipmentInspectionStore = defineStore("equipmentInspection", {
};
},
actions: {
fetchInspectionForEquipment(offset = 0, count = 25, search = "", clear = false) {
fetchInspectionForEquipment(offset = 0, count = 25, clear = false) {
const equipmentId = useEquipmentStore().activeEquipment;
this.inspections = inspectionDemoData
.filter((idd) => idd.relatedId == equipmentId)
.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.inspections.length;
this.loading = "fetched";
return;
if (clear) this.inspections = [];
this.loading = "loading";
http
.get(
`/admin/equipment/${equipmentId}/inspection?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
)
.get(`/admin/inspection/equipment/${equipmentId}?offset=${offset}&count=${count}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.inspections

View file

@ -3,10 +3,9 @@ import type {
EquipmentTypeViewModel,
CreateEquipmentTypeViewModel,
UpdateEquipmentTypeViewModel,
} from "@/viewmodels/admin/unit/equipmentType/equipmentType.models";
} from "@/viewmodels/admin/unit/equipment/equipmentType.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { equipmentTypeDemoData } from "@/demodata/equipmentType";
export const useEquipmentTypeStore = defineStore("equipmentType", {
state: () => {
@ -21,17 +20,13 @@ export const useEquipmentTypeStore = defineStore("equipmentType", {
},
actions: {
fetchEquipmentTypes(offset = 0, count = 25, search = "", clear = false) {
this.equipmentTypes = equipmentTypeDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.equipmentTypes.length;
this.loading = "fetched";
return;
if (clear) this.equipmentTypes = [];
this.loading = "loading";
http
.get(`/admin/equipmentType?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.equipments
result.data.equipmentTypes
.filter((elem: EquipmentTypeViewModel) => this.equipmentTypes.findIndex((m) => m.id == elem.id) == -1)
.map((elem: EquipmentTypeViewModel, index: number): EquipmentTypeViewModel & { tab_pos: number } => {
return {
@ -50,20 +45,15 @@ export const useEquipmentTypeStore = defineStore("equipmentType", {
},
async getAllEquipmentTypes(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/equipmentType?noLimit=true`).then((res) => {
return { ...res, data: res.data.equipments };
return { ...res, data: res.data.equipmentTypes };
});
},
async searchEquipmentTypes(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/equipmentType?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.equipments };
return { ...res, data: res.data.equipmentTypes };
});
},
fetchEquipmentTypeByActiveId() {
this.activeEquipmentTypeObj = equipmentTypeDemoData.find(
(e) => e.id == this.activeEquipmentType
) as EquipmentTypeViewModel;
this.loadingActive = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/equipmentType/${this.activeEquipmentType}`)
@ -80,14 +70,16 @@ export const useEquipmentTypeStore = defineStore("equipmentType", {
},
async createEquipmentType(equipmentType: CreateEquipmentTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/equipmentType`, {
// TODO: data
type: equipmentType.type,
description: equipmentType.description,
});
this.fetchEquipmentTypes();
return result;
},
async updateActiveEquipmentType(equipmentType: UpdateEquipmentTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/equipmentType/${equipmentType.id}`, {
// TODO: data
type: equipmentType.type,
description: equipmentType.description,
});
this.fetchEquipmentTypes();
return result;

View file

@ -1,14 +1,6 @@
import { defineStore } from "pinia";
import type {
EquipmentTypeViewModel,
CreateEquipmentTypeViewModel,
UpdateEquipmentTypeViewModel,
} from "@/viewmodels/admin/unit/equipmentType/equipmentType.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { equipmentTypeDemoData } from "@/demodata/equipmentType";
import type { InspectionPlanViewModel } from "@/viewmodels/admin/unit/inspectionPlan/inspectionPlan.models";
import { inspectionPlanDemoData } from "@/demodata/inspectionPlan";
import type { InspectionPlanViewModel } from "@/viewmodels/admin/unit/inspection/inspectionPlan.models";
import { useEquipmentTypeStore } from "./equipmentType";
export const useEquipmentTypeInspectionPlanStore = defineStore("equipmentTypeInspectionPlan", {
@ -21,12 +13,9 @@ export const useEquipmentTypeInspectionPlanStore = defineStore("equipmentTypeIns
actions: {
fetchInspectionPlanForEquipmentType() {
const equipmentTypeId = useEquipmentTypeStore().activeEquipmentType;
this.inspectionPlans = inspectionPlanDemoData.filter((ipdd) => ipdd.relatedId == equipmentTypeId);
this.loading = "fetched";
return;
this.loading = "loading";
http
.get(`/admin/equipmentType/${equipmentTypeId}/inspectionPlan`)
.get(`/admin/inspectionPlan/equipmentType/${equipmentTypeId}`)
.then((result) => {
this.inspectionPlans = result.data;
this.loading = "fetched";

View file

@ -1,7 +1,6 @@
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", {
@ -14,10 +13,6 @@ export const useInspectionStore = defineStore("inspection", {
},
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}`)
@ -34,14 +29,17 @@ export const useInspectionStore = defineStore("inspection", {
},
async createInspection(inspection: any): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/inspection`, {
// TODO: data
context: "",
inspectionPlanId: "",
relatedId: "",
assigned: "equipment|vehicle",
});
this.fetchInspectionByActiveId();
return result;
},
async updateActiveInspection(inspection: any): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/inspection/${inspection.id}`, {
// TODO: data
context: "",
});
this.fetchInspectionByActiveId();
return result;

View file

@ -3,10 +3,9 @@ import type {
InspectionPlanViewModel,
CreateInspectionPlanViewModel,
UpdateInspectionPlanViewModel,
} from "@/viewmodels/admin/unit/inspectionPlan/inspectionPlan.models";
} from "@/viewmodels/admin/unit/inspection/inspectionPlan.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { inspectionPlanDemoData } from "@/demodata/inspectionPlan";
export const useInspectionPlanStore = defineStore("inspectionPlan", {
state: () => {
@ -21,10 +20,6 @@ export const useInspectionPlanStore = defineStore("inspectionPlan", {
},
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
@ -53,26 +48,12 @@ export const useInspectionPlanStore = defineStore("inspectionPlan", {
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.loadingActive = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/inspectionPlan/${this.activeInspectionPlan}`)
@ -89,14 +70,20 @@ export const useInspectionPlanStore = defineStore("inspectionPlan", {
},
async createInspectionPlan(inspectionPlan: CreateInspectionPlanViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/inspectionPlan`, {
// TODO: data
title: inspectionPlan.title,
inspectionInterval: inspectionPlan.inspectionInterval,
remindTime: inspectionPlan.remindTime,
relatedId: inspectionPlan.relatedId,
assigned: inspectionPlan.assigned,
});
this.fetchInspectionPlans();
return result;
},
async updateActiveInspectionPlan(inspectionPlan: UpdateInspectionPlanViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/inspectionPlan/${inspectionPlan.id}`, {
// TODO: data
title: inspectionPlan.title,
inspectionInterval: inspectionPlan.inspectionInterval,
remindTime: inspectionPlan.remindTime,
});
this.fetchInspectionPlans();
return result;

View file

@ -3,10 +3,9 @@ import type {
RespiratoryGearViewModel,
CreateRespiratoryGearViewModel,
UpdateRespiratoryGearViewModel,
} from "@/viewmodels/admin/unit/respiratoryGear/respiratoryGear.models";
} from "@/viewmodels/admin/unit/respiratory/respiratoryGear.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { respiratoryGearDemoData } from "@/demodata/respiratoryGear";
export const useRespiratoryGearStore = defineStore("respiratoryGear", {
state: () => {
@ -21,10 +20,6 @@ export const useRespiratoryGearStore = defineStore("respiratoryGear", {
},
actions: {
fetchRespiratoryGears(offset = 0, count = 25, search = "", clear = false) {
this.respiratoryGears = respiratoryGearDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.respiratoryGears.length;
this.loading = "fetched";
return;
if (clear) this.respiratoryGears = [];
this.loading = "loading";
http
@ -59,11 +54,6 @@ export const useRespiratoryGearStore = defineStore("respiratoryGear", {
});
},
fetchRespiratoryGearByActiveId() {
this.activeRespiratoryGearObj = respiratoryGearDemoData.find(
(e) => e.id == this.activeRespiratoryGear
) as RespiratoryGearViewModel;
this.loading = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/respiratoryGear/${this.activeRespiratoryGear}`)

View file

@ -3,10 +3,9 @@ import type {
RespiratoryMissionViewModel,
CreateRespiratoryMissionViewModel,
UpdateRespiratoryMissionViewModel,
} from "@/viewmodels/admin/unit/respiratoryMission/respiratoryMission.models";
} from "@/viewmodels/admin/unit/respiratory/respiratoryMission.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { respiratoryMissionDemoData } from "@/demodata/respiratoryMission";
export const useRespiratoryMissionStore = defineStore("respiratoryMission", {
state: () => {
@ -21,10 +20,6 @@ export const useRespiratoryMissionStore = defineStore("respiratoryMission", {
},
actions: {
fetchRespiratoryMissions(offset = 0, count = 25, search = "", clear = false) {
this.respiratoryMissions = respiratoryMissionDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.respiratoryMissions.length;
this.loading = "fetched";
return;
if (clear) this.respiratoryMissions = [];
this.loading = "loading";
http
@ -63,11 +58,6 @@ export const useRespiratoryMissionStore = defineStore("respiratoryMission", {
});
},
fetchRespiratoryMissionByActiveId() {
this.activeRespiratoryMissionObj = this.respiratoryMissions.find(
(e) => e.id == this.activeRespiratoryMission
) as RespiratoryMissionViewModel;
this.loading = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/respiratoryMission/${this.activeRespiratoryMission}`)

View file

@ -3,10 +3,9 @@ import type {
RespiratoryWearerViewModel,
CreateRespiratoryWearerViewModel,
UpdateRespiratoryWearerViewModel,
} from "@/viewmodels/admin/unit/respiratoryWearer/respiratoryWearer.models";
} from "@/viewmodels/admin/unit/respiratory/respiratoryWearer.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { respiratoryWearerDemoData } from "@/demodata/respiratoryWearer";
export const useRespiratoryWearerStore = defineStore("respiratoryWearer", {
state: () => {
@ -21,10 +20,6 @@ export const useRespiratoryWearerStore = defineStore("respiratoryWearer", {
},
actions: {
fetchRespiratoryWearers(offset = 0, count = 25, search = "", clear = false) {
this.respiratoryWearers = respiratoryWearerDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.respiratoryWearers.length;
this.loading = "fetched";
return;
if (clear) this.respiratoryWearers = [];
this.loading = "loading";
http
@ -63,11 +58,6 @@ export const useRespiratoryWearerStore = defineStore("respiratoryWearer", {
});
},
fetchRespiratoryWearerByActiveId() {
this.activeRespiratoryWearerObj = respiratoryWearerDemoData.find(
(e) => e.id == this.activeRespiratoryWearer
) as RespiratoryWearerViewModel;
this.loading = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/respiratoryWearer/${this.activeRespiratoryWearer}`)

View file

@ -1,8 +1,7 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import { useVehicleStore } from "./vehicle";
import type { DamageReportViewModel } from "@/viewmodels/admin/unit/damageReport/damageReport.models";
import { damageReportDemoData } from "@/demodata/damageReport";
import type { DamageReportViewModel } from "@/viewmodels/admin/unit/damageReport.models";
export const useVehicleDamageReportStore = defineStore("vehicleDamageReport", {
state: () => {
@ -15,17 +14,11 @@ export const useVehicleDamageReportStore = defineStore("vehicleDamageReport", {
actions: {
fetchDamageReportForVehicle(offset = 0, count = 25, search = "", clear = false) {
const vehicleId = useVehicleStore().activeVehicle;
this.damageReports = damageReportDemoData
.filter((drdd) => drdd.relatedId == vehicleId)
.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.damageReports.length;
this.loading = "fetched";
return;
if (clear) this.damageReports = [];
this.loading = "loading";
http
.get(
`/admin/vehicle/${vehicleId}/damageReport?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
`/admin/damagereport/vehicle/${vehicleId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
)
.then((result) => {
this.totalCount = result.data.total;

View file

@ -1,7 +1,6 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { InspectionViewModel } from "@/viewmodels/admin/unit/inspection/inspection.models";
import { inspectionDemoData } from "@/demodata/inspectionPlan";
import { useVehicleStore } from "./vehicle";
export const useVehicleInspectionStore = defineStore("vehicleInspection", {
@ -15,17 +14,11 @@ export const useVehicleInspectionStore = defineStore("vehicleInspection", {
actions: {
fetchInspectionForVehicle(offset = 0, count = 25, search = "", clear = false) {
const vehicleId = useVehicleStore().activeVehicle;
this.inspections = inspectionDemoData
.filter((idd) => idd.relatedId == vehicleId)
.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.inspections.length;
this.loading = "fetched";
return;
if (clear) this.inspections = [];
this.loading = "loading";
http
.get(
`/admin/vehicle/${vehicleId}/inspection?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
`/admin/inspection/vehicle/${vehicleId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
)
.then((result) => {
this.totalCount = result.data.total;

View file

@ -6,7 +6,6 @@ import type {
} from "@/viewmodels/admin/unit/vehicle/vehicle.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { vehicleDemoData } from "@/demodata/vehicle";
export const useVehicleStore = defineStore("vehicle", {
state: () => {
@ -21,10 +20,6 @@ export const useVehicleStore = defineStore("vehicle", {
},
actions: {
fetchVehicles(offset = 0, count = 25, search = "", clear = false) {
this.vehicles = vehicleDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.vehicles.length;
this.loading = "fetched";
return;
if (clear) this.vehicles = [];
this.loading = "loading";
http
@ -68,9 +63,6 @@ export const useVehicleStore = defineStore("vehicle", {
});
},
fetchVehicleByActiveId() {
this.activeVehicleObj = vehicleDemoData.find((e) => e.id == this.activeVehicle) as VehicleViewModel;
this.loadingActive = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/vehicle/${this.activeVehicle}`)
@ -87,14 +79,22 @@ export const useVehicleStore = defineStore("vehicle", {
},
async createVehicle(vehicle: CreateVehicleViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/vehicle`, {
// TODO: data
vehicleTypeId: vehicle.vehicleTypeId,
name: vehicle.name,
code: vehicle.code,
location: vehicle.location,
commissioned: vehicle.commissioned,
});
this.fetchVehicles();
return result;
},
async updateActiveVehicle(vehicle: UpdateVehicleViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/vehicle/${vehicle.id}`, {
// TODO: data
name: vehicle.name,
code: vehicle.code,
location: vehicle.location,
commissioned: vehicle.commissioned,
decommissioned: vehicle.decommissioned,
});
this.fetchVehicles();
return result;

View file

@ -1,14 +1,6 @@
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";
import type { InspectionPlanViewModel } from "@/viewmodels/admin/unit/inspectionPlan/inspectionPlan.models";
import { inspectionPlanDemoData } from "@/demodata/inspectionPlan";
import type { InspectionPlanViewModel } from "@/viewmodels/admin/unit/inspection/inspectionPlan.models";
import { useVehicleTypeStore } from "./vehicleType";
export const useVehicleTypeInspectionPlanStore = defineStore("vehicleTypeInspectionPlan", {
@ -22,12 +14,9 @@ export const useVehicleTypeInspectionPlanStore = defineStore("vehicleTypeInspect
actions: {
fetchInspectionPlanForVehicleType() {
const vehicleTypeId = useVehicleTypeStore().activeVehicleType;
this.inspectionPlans = inspectionPlanDemoData.filter((ipdd) => ipdd.relatedId == vehicleTypeId);
this.loading = "fetched";
return;
this.loading = "loading";
http
.get(`/admin/vehicleType/${vehicleTypeId}/inspectionPlan`)
.get(`/admin/inspectionPlan/vehicleType/${vehicleTypeId}`)
.then((result) => {
this.inspectionPlans = result.data;
this.loading = "fetched";

View file

@ -3,10 +3,9 @@ import type {
VehicleTypeViewModel,
CreateVehicleTypeViewModel,
UpdateVehicleTypeViewModel,
} from "@/viewmodels/admin/unit/vehicleType/vehicleType.models";
} from "@/viewmodels/admin/unit/vehicle/vehicleType.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { vehicleTypeDemoData } from "@/demodata/vehicleType";
export const useVehicleTypeStore = defineStore("vehicleType", {
state: () => {
@ -21,17 +20,13 @@ export const useVehicleTypeStore = defineStore("vehicleType", {
},
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
result.data.vehicleTypes
.filter((elem: VehicleTypeViewModel) => this.vehicleTypes.findIndex((m) => m.id == elem.id) == -1)
.map((elem: VehicleTypeViewModel, index: number): VehicleTypeViewModel & { tab_pos: number } => {
return {
@ -50,20 +45,15 @@ export const useVehicleTypeStore = defineStore("vehicleType", {
},
async getAllVehicleTypes(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/vehicleType?noLimit=true`).then((res) => {
return { ...res, data: res.data.vehicles };
return { ...res, data: res.data.vehicleTypes };
});
},
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 };
return { ...res, data: res.data.vehicleTypes };
});
},
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}`)
@ -80,14 +70,16 @@ export const useVehicleTypeStore = defineStore("vehicleType", {
},
async createVehicleType(vehicleType: CreateVehicleTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/vehicleType`, {
// TODO: data
type: vehicleType.type,
description: vehicleType.description,
});
this.fetchVehicleTypes();
return result;
},
async updateActiveVehicleType(vehicleType: UpdateVehicleTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/vehicleType/${vehicleType.id}`, {
// TODO: data
type: vehicleType.type,
description: vehicleType.description,
});
this.fetchVehicleTypes();
return result;

View file

@ -1,8 +1,7 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import { useWearableStore } from "./wearable";
import type { DamageReportViewModel } from "@/viewmodels/admin/unit/damageReport/damageReport.models";
import { damageReportDemoData } from "@/demodata/damageReport";
import type { DamageReportViewModel } from "@/viewmodels/admin/unit/damageReport.models";
export const useWearableDamageReportStore = defineStore("wearableDamageReport", {
state: () => {
@ -15,17 +14,11 @@ export const useWearableDamageReportStore = defineStore("wearableDamageReport",
actions: {
fetchDamageReportForWearable(offset = 0, count = 25, search = "", clear = false) {
const wearableId = useWearableStore().activeWearable;
this.damageReports = damageReportDemoData
.filter((drdd) => drdd.relatedId == wearableId)
.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.damageReports.length;
this.loading = "fetched";
return;
if (clear) this.damageReports = [];
this.loading = "loading";
http
.get(
`/admin/wearable/${wearableId}/damageReport?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
`/admin/damagereport/wearable/${wearableId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
)
.then((result) => {
this.totalCount = result.data.total;

View file

@ -6,7 +6,6 @@ import type {
} from "@/viewmodels/admin/unit/wearable/wearable.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { wearableDemoData } from "@/demodata/wearable";
export const useWearableStore = defineStore("wearable", {
state: () => {
@ -21,10 +20,6 @@ export const useWearableStore = defineStore("wearable", {
},
actions: {
fetchWearables(offset = 0, count = 25, search = "", clear = false) {
this.wearables = wearableDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.wearables.length;
this.loading = "fetched";
return;
if (clear) this.wearables = [];
this.loading = "loading";
http
@ -68,9 +63,6 @@ export const useWearableStore = defineStore("wearable", {
});
},
fetchWearableByActiveId() {
this.activeWearableObj = wearableDemoData.find((e) => e.id == this.activeWearable) as WearableViewModel;
this.loadingActive = "fetched";
return;
this.loadingActive = "loading";
http
.get(`/admin/wearable/${this.activeWearable}`)
@ -87,14 +79,24 @@ export const useWearableStore = defineStore("wearable", {
},
async createWearable(wearable: CreateWearableViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/wearable`, {
// TODO: data
wearableTypeId: wearable.wearableTypeId,
name: wearable.name,
code: wearable.code,
location: wearable.location,
commissioned: wearable.commissioned,
wearerId: wearable.wearerId,
});
this.fetchWearables();
return result;
},
async updateActiveWearable(wearable: UpdateWearableViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/wearable/${wearable.id}`, {
// TODO: data
name: wearable.name,
code: wearable.code,
location: wearable.location,
commissioned: wearable.commissioned,
decommissioned: wearable.decommissioned,
wearerId: wearable.wearerId,
});
this.fetchWearables();
return result;

View file

@ -3,10 +3,9 @@ import type {
WearableTypeViewModel,
CreateWearableTypeViewModel,
UpdateWearableTypeViewModel,
} from "@/viewmodels/admin/unit/wearableType/wearableType.models";
} from "@/viewmodels/admin/unit/wearable/wearableType.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import { wearableTypeDemoData } from "@/demodata/wearableType";
export const useWearableTypeStore = defineStore("wearableType", {
state: () => {
@ -18,17 +17,13 @@ export const useWearableTypeStore = defineStore("wearableType", {
},
actions: {
fetchWearableTypes(offset = 0, count = 25, search = "", clear = false) {
this.wearableTypes = wearableTypeDemoData.map((e, i) => ({ ...e, tab_pos: i }));
this.totalCount = this.wearableTypes.length;
this.loading = "fetched";
return;
if (clear) this.wearableTypes = [];
this.loading = "loading";
http
.get(`/admin/wearableType?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.wearables
result.data.wearableTypes
.filter((elem: WearableTypeViewModel) => this.wearableTypes.findIndex((m) => m.id == elem.id) == -1)
.map((elem: WearableTypeViewModel, index: number): WearableTypeViewModel & { tab_pos: number } => {
return {
@ -47,12 +42,12 @@ export const useWearableTypeStore = defineStore("wearableType", {
},
async getAllWearableTypes(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/wearableType?noLimit=true`).then((res) => {
return { ...res, data: res.data.wearables };
return { ...res, data: res.data.wearableTypes };
});
},
async searchWearableTypes(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/wearableType?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.wearables };
return { ...res, data: res.data.wearableTypes };
});
},
fetchWearableTypeById(id: string) {
@ -60,14 +55,16 @@ export const useWearableTypeStore = defineStore("wearableType", {
},
async createWearableType(wearableType: CreateWearableTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/wearableType`, {
// TODO: data
type: wearableType.type,
description: wearableType.description,
});
this.fetchWearableTypes();
return result;
},
async updateWearableType(wearableType: UpdateWearableTypeViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/wearableType/${wearableType.id}`, {
// TODO: data
type: wearableType.type,
description: wearableType.description,
});
this.fetchWearableTypes();
return result;