42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
|
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";
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
});
|