repair create and view
This commit is contained in:
parent
b5a3ff4dc6
commit
c79d5bb1cd
18 changed files with 1046 additions and 59 deletions
|
@ -74,6 +74,23 @@ export const useDamageReportStore = defineStore("damageReport", {
|
|||
return { ...res, data: res.data.damageReports };
|
||||
});
|
||||
},
|
||||
async getAllDamageReportsWithRelated(
|
||||
related: "vehicle" | "equipment" | "wearable",
|
||||
relatedId: string
|
||||
): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/damageReport/${related}/${relatedId}?noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.damageReports };
|
||||
});
|
||||
},
|
||||
async searchDamageReportsWithRelated(
|
||||
related: "vehicle" | "equipment" | "wearable",
|
||||
relatedId: string,
|
||||
search: string
|
||||
): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/damageReport/${related}/${relatedId}?search=${search}&noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.damageReports };
|
||||
});
|
||||
},
|
||||
fetchDamageReportByActiveId() {
|
||||
this.loadingActive = "loading";
|
||||
http
|
||||
|
|
43
src/stores/admin/unit/equipment/repair.ts
Normal file
43
src/stores/admin/unit/equipment/repair.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { http } from "@/serverCom";
|
||||
import { useEquipmentStore } from "./equipment";
|
||||
import type { RepairViewModel } from "@/viewmodels/admin/unit/repair.models";
|
||||
|
||||
export const useEquipmentRepairStore = defineStore("equipmentRepair", {
|
||||
state: () => {
|
||||
return {
|
||||
repairs: [] as Array<RepairViewModel & { tab_pos: number }>,
|
||||
totalCount: 0 as number,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchRepairForEquipment(offset = 0, count = 25, search = "", clear = false) {
|
||||
const equipmentId = useEquipmentStore().activeEquipment;
|
||||
if (clear) this.repairs = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(
|
||||
`/admin/repair/equipment/${equipmentId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
|
||||
)
|
||||
.then((result) => {
|
||||
this.totalCount = result.data.total;
|
||||
result.data.repairs
|
||||
.filter((elem: RepairViewModel) => this.repairs.findIndex((m) => m.id == elem.id) == -1)
|
||||
.map((elem: RepairViewModel, index: number): RepairViewModel & { tab_pos: number } => {
|
||||
return {
|
||||
...elem,
|
||||
tab_pos: index + offset,
|
||||
};
|
||||
})
|
||||
.forEach((elem: RepairViewModel & { tab_pos: number }) => {
|
||||
this.repairs.push(elem);
|
||||
});
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
|
@ -1,5 +1,9 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type { RepairViewModel, UpdateRepairViewModel } from "@/viewmodels/admin/unit/repair.models";
|
||||
import type {
|
||||
CreateRepairViewModel,
|
||||
RepairViewModel,
|
||||
UpdateRepairViewModel,
|
||||
} from "@/viewmodels/admin/unit/repair.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
|
@ -94,6 +98,17 @@ export const useRepairStore = defineStore("repair", {
|
|||
responseType: "blob",
|
||||
});
|
||||
},
|
||||
async createRepair(repair: CreateRepairViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post(`/admin/repair`, {
|
||||
affected: repair.affected,
|
||||
affectedId: repair.affectedId,
|
||||
title: repair.title,
|
||||
description: repair.description,
|
||||
responsible: repair.responsible,
|
||||
reports: repair.reports,
|
||||
});
|
||||
return result;
|
||||
},
|
||||
async updateRepair(repair: UpdateRepairViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/repair/${repair.id}`, {
|
||||
status: repair.status,
|
||||
|
|
43
src/stores/admin/unit/vehicle/repair.ts
Normal file
43
src/stores/admin/unit/vehicle/repair.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { http } from "@/serverCom";
|
||||
import { useVehicleStore } from "./vehicle";
|
||||
import type { RepairViewModel } from "@/viewmodels/admin/unit/repair.models";
|
||||
|
||||
export const useVehicleRepairStore = defineStore("vehicleRepair", {
|
||||
state: () => {
|
||||
return {
|
||||
repairs: [] as Array<RepairViewModel & { tab_pos: number }>,
|
||||
totalCount: 0 as number,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchRepairForVehicle(offset = 0, count = 25, search = "", clear = false) {
|
||||
const vehicleId = useVehicleStore().activeVehicle;
|
||||
if (clear) this.repairs = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(
|
||||
`/admin/repair/vehicle/${vehicleId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
|
||||
)
|
||||
.then((result) => {
|
||||
this.totalCount = result.data.total;
|
||||
result.data.repairs
|
||||
.filter((elem: RepairViewModel) => this.repairs.findIndex((m) => m.id == elem.id) == -1)
|
||||
.map((elem: RepairViewModel, index: number): RepairViewModel & { tab_pos: number } => {
|
||||
return {
|
||||
...elem,
|
||||
tab_pos: index + offset,
|
||||
};
|
||||
})
|
||||
.forEach((elem: RepairViewModel & { tab_pos: number }) => {
|
||||
this.repairs.push(elem);
|
||||
});
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
43
src/stores/admin/unit/wearable/repair.ts
Normal file
43
src/stores/admin/unit/wearable/repair.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { http } from "@/serverCom";
|
||||
import { useWearableStore } from "./wearable";
|
||||
import type { RepairViewModel } from "@/viewmodels/admin/unit/repair.models";
|
||||
|
||||
export const useWearableRepairStore = defineStore("wearableRepair", {
|
||||
state: () => {
|
||||
return {
|
||||
repairs: [] as Array<RepairViewModel & { tab_pos: number }>,
|
||||
totalCount: 0 as number,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchRepairForWearable(offset = 0, count = 25, search = "", clear = false) {
|
||||
const wearableId = useWearableStore().activeWearable;
|
||||
if (clear) this.repairs = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(
|
||||
`/admin/repair/wearable/${wearableId}?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
|
||||
)
|
||||
.then((result) => {
|
||||
this.totalCount = result.data.total;
|
||||
result.data.repairs
|
||||
.filter((elem: RepairViewModel) => this.repairs.findIndex((m) => m.id == elem.id) == -1)
|
||||
.map((elem: RepairViewModel, index: number): RepairViewModel & { tab_pos: number } => {
|
||||
return {
|
||||
...elem,
|
||||
tab_pos: index + offset,
|
||||
};
|
||||
})
|
||||
.forEach((elem: RepairViewModel & { tab_pos: number }) => {
|
||||
this.repairs.push(elem);
|
||||
});
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue