import { defineStore } from "pinia"; import { http } from "@/serverCom"; import type { AxiosResponse } from "axios"; import type { ProtocolAgendaViewModel, SyncProtocolAgendaViewModel, } from "../../viewmodels/admin/protocolAgenda.models"; import { useProtocolStore } from "./protocol"; export const useProtocolAgendaStore = defineStore("protocolAgenda", { state: () => { return { agenda: [] as Array, loading: "loading" as "loading" | "fetched" | "failed", }; }, actions: { fetchProtocolAgenda() { const protocolId = useProtocolStore().activeProtocol; this.loading = "loading"; http .get(`/admin/protocol/${protocolId}/agenda`) .then((result) => { this.agenda = result.data; this.loading = "fetched"; }) .catch((err) => { this.loading = "failed"; }); }, async synchronizeActiveProtocolAgenda( agenda: Array ): Promise> { const protocolId = useProtocolStore().activeProtocol; const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/agenda`, { agenda: agenda, }); this.fetchProtocolAgenda(); return result; }, }, });