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, 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 ): Promise> { const protocolId = useProtocolStore().activeProtocol; const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/presence`, { presence: presence, }); this.fetchProtocolPresence(); return result; }, }, });