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

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-10-13 15:47:52 +02:00
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
ProtocolPresenceViewModel,
SyncProtocolPresenceViewModel,
} from "../../viewmodels/admin/protocolPresence.models";
import { useProtocolStore } from "./protocol";
export const useProtocolPresenceStore = defineStore("protocolPresence", {
state: () => {
return {
presence: [] as Array<ProtocolPresenceViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchProtocolPresence() {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/presence`)
.then((result) => {
this.presence = result.data;
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async synchronizeActiveProtocolPresence(
presence: Array<SyncProtocolPresenceViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/presence`, {
presence: presence,
});
this.fetchProtocolPresence();
return result;
},
},
});