ff-admin/src/stores/admin/user.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-09-01 14:54:49 +02:00
import { defineStore } from "pinia";
import type { UserViewModel } from "../../viewmodels/admin/user.models";
import { http } from "../../serverCom";
export const useUserStore = defineStore("user", {
state: () => {
return {
users: [] as Array<UserViewModel>,
user: null as null | UserViewModel,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchUsers() {
this.loadingAll = "loading";
http
.get("/admin/user")
.then((result) => {
this.users = result.data;
this.loadingAll = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
});
},
fetchUsersById(id: number) {
this.user = null;
this.loadingSingle = "loading";
http
.get(`/admin/user/${id}`)
.then((result) => {
this.user = result.data;
this.loadingSingle = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
});
},
},
});