base components on collections

This commit is contained in:
Julian Krauser 2025-03-25 10:42:40 +01:00
parent b6d6dd0796
commit 3e87bbc267
24 changed files with 1347 additions and 57 deletions

View file

@ -0,0 +1,99 @@
import { defineStore } from "pinia";
import type {
DamageReportViewModel,
CreateDamageReportViewModel,
UpdateDamageReportViewModel,
} from "@/viewmodels/admin/unit/damageReport/damageReport.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
export const useDamageReportStore = defineStore("damageReport", {
state: () => {
return {
damageReports: [] as Array<DamageReportViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchDamageReports(offset = 0, count = 25, search = "", clear = false) {
if (clear) this.damageReports = [];
this.loading = "loading";
http
.get(`/admin/damageReport?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.damageReports
.filter((elem: DamageReportViewModel) => this.damageReports.findIndex((m) => m.id == elem.id) == -1)
.map((elem: DamageReportViewModel, index: number): DamageReportViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
})
.forEach((elem: DamageReportViewModel & { tab_pos: number }) => {
this.damageReports.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async getAllDamageReports(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/damageReport?noLimit=true`).then((res) => {
return { ...res, data: res.data.damageReports };
});
},
async getDamageReportsByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
return await http
.post(`/admin/damageReport/ids`, {
ids,
})
.then((res) => {
return { ...res, data: res.data.damageReports };
});
},
async searchDamageReports(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/damageReport?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.damageReports };
});
},
fetchDamageReportById(id: string) {
return http.get(`/admin/damageReport/${id}`);
},
fetchDamageReportStatisticsById(id: string) {
return http.get(`/admin/damageReport/${id}/statistics`);
},
async createDamageReport(damageReport: CreateDamageReportViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/damageReport`, {
salutationId: damageReport.salutationId,
firstname: damageReport.firstname,
lastname: damageReport.lastname,
nameaffix: damageReport.nameaffix,
birthdate: damageReport.birthdate,
internalId: damageReport.internalId,
});
this.fetchDamageReports();
return result;
},
async updateDamageReport(damageReport: UpdateDamageReportViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/damageReport/${damageReport.id}`, {
salutationId: damageReport.salutationId,
firstname: damageReport.firstname,
lastname: damageReport.lastname,
nameaffix: damageReport.nameaffix,
birthdate: damageReport.birthdate,
internalId: damageReport.internalId,
});
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

@ -0,0 +1,120 @@
import { defineStore } from "pinia";
import type {
RespiratoryGearViewModel,
CreateRespiratoryGearViewModel,
UpdateRespiratoryGearViewModel,
} from "@/viewmodels/admin/unit/respiratoryGear/respiratoryGear.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
export const useRespiratoryGearStore = defineStore("respiratoryGear", {
state: () => {
return {
respiratoryGears: [] as Array<RespiratoryGearViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
activeRespiratoryGear: null as string | null,
activeRespiratoryGearObj: null as RespiratoryGearViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchRespiratoryGears(offset = 0, count = 25, search = "", clear = false) {
if (clear) this.respiratoryGears = [];
this.loading = "loading";
http
.get(`/admin/respiratoryGear?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.respiratoryGears
.filter((elem: RespiratoryGearViewModel) => this.respiratoryGears.findIndex((m) => m.id == elem.id) == -1)
.map((elem: RespiratoryGearViewModel, index: number): RespiratoryGearViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
})
.forEach((elem: RespiratoryGearViewModel & { tab_pos: number }) => {
this.respiratoryGears.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async getAllRespiratoryGears(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/respiratoryGear?noLimit=true`).then((res) => {
return { ...res, data: res.data.respiratoryGears };
});
},
async getRespiratoryGearsByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
return await http
.post(`/admin/respiratoryGear/ids`, {
ids,
})
.then((res) => {
return { ...res, data: res.data.respiratoryGears };
});
},
async searchRespiratoryGears(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/respiratoryGear?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.respiratoryGears };
});
},
fetchRespiratoryGearByActiveId() {
this.loadingActive = "loading";
http
.get(`/admin/respiratoryGear/${this.activeRespiratoryGear}`)
.then((res) => {
this.activeRespiratoryGearObj = res.data;
this.loadingActive = "fetched";
})
.catch((err) => {
this.loadingActive = "failed";
});
},
fetchRespiratoryGearById(id: string) {
return http.get(`/admin/respiratoryGear/${id}`);
},
async printRespiratoryGearByActiveId() {
return http.get(`/admin/respiratoryGear/${this.activeRespiratoryGear}/print`, {
responseType: "blob",
});
},
fetchRespiratoryGearStatisticsById(id: string) {
return http.get(`/admin/respiratoryGear/${id}/statistics`);
},
async createRespiratoryGear(respiratoryGear: CreateRespiratoryGearViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/respiratoryGear`, {
salutationId: respiratoryGear.salutationId,
firstname: respiratoryGear.firstname,
lastname: respiratoryGear.lastname,
nameaffix: respiratoryGear.nameaffix,
birthdate: respiratoryGear.birthdate,
internalId: respiratoryGear.internalId,
});
this.fetchRespiratoryGears();
return result;
},
async updateActiveRespiratoryGear(
respiratoryGear: UpdateRespiratoryGearViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/respiratoryGear/${respiratoryGear.id}`, {
salutationId: respiratoryGear.salutationId,
firstname: respiratoryGear.firstname,
lastname: respiratoryGear.lastname,
nameaffix: respiratoryGear.nameaffix,
birthdate: respiratoryGear.birthdate,
internalId: respiratoryGear.internalId,
});
this.fetchRespiratoryGears();
return result;
},
async deleteRespiratoryGear(respiratoryGear: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/respiratoryGear/${respiratoryGear}`);
this.fetchRespiratoryGears();
return result;
},
},
});

View file

@ -0,0 +1,126 @@
import { defineStore } from "pinia";
import type {
RespiratoryMissionViewModel,
CreateRespiratoryMissionViewModel,
UpdateRespiratoryMissionViewModel,
} from "@/viewmodels/admin/unit/respiratoryMission/respiratoryMission.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
export const useRespiratoryMissionStore = defineStore("respiratoryMission", {
state: () => {
return {
respiratoryMissions: [] as Array<RespiratoryMissionViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
activeRespiratoryMission: null as string | null,
activeRespiratoryMissionObj: null as RespiratoryMissionViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchRespiratoryMissions(offset = 0, count = 25, search = "", clear = false) {
if (clear) this.respiratoryMissions = [];
this.loading = "loading";
http
.get(`/admin/respiratoryMission?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.respiratoryMissions
.filter(
(elem: RespiratoryMissionViewModel) => this.respiratoryMissions.findIndex((m) => m.id == elem.id) == -1
)
.map(
(elem: RespiratoryMissionViewModel, index: number): RespiratoryMissionViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
}
)
.forEach((elem: RespiratoryMissionViewModel & { tab_pos: number }) => {
this.respiratoryMissions.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async getAllRespiratoryMissions(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/respiratoryMission?noLimit=true`).then((res) => {
return { ...res, data: res.data.respiratoryMissions };
});
},
async getRespiratoryMissionsByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
return await http
.post(`/admin/respiratoryMission/ids`, {
ids,
})
.then((res) => {
return { ...res, data: res.data.respiratoryMissions };
});
},
async searchRespiratoryMissions(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/respiratoryMission?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.respiratoryMissions };
});
},
fetchRespiratoryMissionByActiveId() {
this.loadingActive = "loading";
http
.get(`/admin/respiratoryMission/${this.activeRespiratoryMission}`)
.then((res) => {
this.activeRespiratoryMissionObj = res.data;
this.loadingActive = "fetched";
})
.catch((err) => {
this.loadingActive = "failed";
});
},
fetchRespiratoryMissionById(id: string) {
return http.get(`/admin/respiratoryMission/${id}`);
},
async printRespiratoryMissionByActiveId() {
return http.get(`/admin/respiratoryMission/${this.activeRespiratoryMission}/print`, {
responseType: "blob",
});
},
fetchRespiratoryMissionStatisticsById(id: string) {
return http.get(`/admin/respiratoryMission/${id}/statistics`);
},
async createRespiratoryMission(
respiratoryMission: CreateRespiratoryMissionViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/respiratoryMission`, {
salutationId: respiratoryMission.salutationId,
firstname: respiratoryMission.firstname,
lastname: respiratoryMission.lastname,
nameaffix: respiratoryMission.nameaffix,
birthdate: respiratoryMission.birthdate,
internalId: respiratoryMission.internalId,
});
this.fetchRespiratoryMissions();
return result;
},
async updateActiveRespiratoryMission(
respiratoryMission: UpdateRespiratoryMissionViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/respiratoryMission/${respiratoryMission.id}`, {
salutationId: respiratoryMission.salutationId,
firstname: respiratoryMission.firstname,
lastname: respiratoryMission.lastname,
nameaffix: respiratoryMission.nameaffix,
birthdate: respiratoryMission.birthdate,
internalId: respiratoryMission.internalId,
});
this.fetchRespiratoryMissions();
return result;
},
async deleteRespiratoryMission(respiratoryMission: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/respiratoryMission/${respiratoryMission}`);
this.fetchRespiratoryMissions();
return result;
},
},
});

View file

@ -0,0 +1,126 @@
import { defineStore } from "pinia";
import type {
RespiratoryWearerViewModel,
CreateRespiratoryWearerViewModel,
UpdateRespiratoryWearerViewModel,
} from "@/viewmodels/admin/unit/respiratoryWearer/respiratoryWearer.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
export const useRespiratoryWearerStore = defineStore("respiratoryWearer", {
state: () => {
return {
respiratoryWearers: [] as Array<RespiratoryWearerViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
activeRespiratoryWearer: null as string | null,
activeRespiratoryWearerObj: null as RespiratoryWearerViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchRespiratoryWearers(offset = 0, count = 25, search = "", clear = false) {
if (clear) this.respiratoryWearers = [];
this.loading = "loading";
http
.get(`/admin/respiratoryWearer?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.respiratoryWearers
.filter(
(elem: RespiratoryWearerViewModel) => this.respiratoryWearers.findIndex((m) => m.id == elem.id) == -1
)
.map(
(elem: RespiratoryWearerViewModel, index: number): RespiratoryWearerViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
}
)
.forEach((elem: RespiratoryWearerViewModel & { tab_pos: number }) => {
this.respiratoryWearers.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async getAllRespiratoryWearers(): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/respiratoryWearer?noLimit=true`).then((res) => {
return { ...res, data: res.data.respiratoryWearers };
});
},
async getRespiratoryWearersByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
return await http
.post(`/admin/respiratoryWearer/ids`, {
ids,
})
.then((res) => {
return { ...res, data: res.data.respiratoryWearers };
});
},
async searchRespiratoryWearers(search: string): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/respiratoryWearer?search=${search}&noLimit=true`).then((res) => {
return { ...res, data: res.data.respiratoryWearers };
});
},
fetchRespiratoryWearerByActiveId() {
this.loadingActive = "loading";
http
.get(`/admin/respiratoryWearer/${this.activeRespiratoryWearer}`)
.then((res) => {
this.activeRespiratoryWearerObj = res.data;
this.loadingActive = "fetched";
})
.catch((err) => {
this.loadingActive = "failed";
});
},
fetchRespiratoryWearerById(id: string) {
return http.get(`/admin/respiratoryWearer/${id}`);
},
async printRespiratoryWearerByActiveId() {
return http.get(`/admin/respiratoryWearer/${this.activeRespiratoryWearer}/print`, {
responseType: "blob",
});
},
fetchRespiratoryWearerStatisticsById(id: string) {
return http.get(`/admin/respiratoryWearer/${id}/statistics`);
},
async createRespiratoryWearer(
respiratoryWearer: CreateRespiratoryWearerViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/respiratoryWearer`, {
salutationId: respiratoryWearer.salutationId,
firstname: respiratoryWearer.firstname,
lastname: respiratoryWearer.lastname,
nameaffix: respiratoryWearer.nameaffix,
birthdate: respiratoryWearer.birthdate,
internalId: respiratoryWearer.internalId,
});
this.fetchRespiratoryWearers();
return result;
},
async updateActiveRespiratoryWearer(
respiratoryWearer: UpdateRespiratoryWearerViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/respiratoryWearer/${respiratoryWearer.id}`, {
salutationId: respiratoryWearer.salutationId,
firstname: respiratoryWearer.firstname,
lastname: respiratoryWearer.lastname,
nameaffix: respiratoryWearer.nameaffix,
birthdate: respiratoryWearer.birthdate,
internalId: respiratoryWearer.internalId,
});
this.fetchRespiratoryWearers();
return result;
},
async deleteRespiratoryWearer(respiratoryWearer: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/respiratoryWearer/${respiratoryWearer}`);
this.fetchRespiratoryWearers();
return result;
},
},
});