ff-admin/src/stores/admin/protocolAgenda.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 {
ProtocolAgendaViewModel,
SyncProtocolAgendaViewModel,
} from "../../viewmodels/admin/protocolAgenda.models";
import { useProtocolStore } from "./protocol";
export const useProtocolAgendaStore = defineStore("protocolAgenda", {
state: () => {
return {
agenda: [] as Array<ProtocolAgendaViewModel>,
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<SyncProtocolAgendaViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/agenda`, {
agenda: agenda,
});
this.fetchProtocolAgenda();
return result;
},
},
});