update usage of salutation

This commit is contained in:
Julian Krauser 2025-01-25 11:57:58 +01:00
parent e330e3a7d6
commit 3866d406b2
9 changed files with 96 additions and 34 deletions

View file

@ -0,0 +1,53 @@
import { defineStore } from "pinia";
import type {
CreateSalutationViewModel,
UpdateSalutationViewModel,
SalutationViewModel,
} from "@/viewmodels/admin/settings/salutation.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
export const useSalutationStore = defineStore("salutation", {
state: () => {
return {
salutations: [] as Array<SalutationViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchSalutations() {
this.loading = "loading";
http
.get("/admin/salutation")
.then((result) => {
this.salutations = result.data;
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchSalutationById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/salutation/${id}`);
},
async createSalutation(salutation: CreateSalutationViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/salutation`, {
salutation: salutation.salutation,
});
this.fetchSalutations();
return result;
},
async updateActiveSalutation(salutation: UpdateSalutationViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/salutation/${salutation.id}`, {
salutation: salutation.salutation,
});
this.fetchSalutations();
return result;
},
async deleteSalutation(salutation: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/salutation/${salutation}`);
this.fetchSalutations();
return result;
},
},
});