43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
|
import { defineStore } from "pinia";
|
||
|
import { http } from "@/serverCom";
|
||
|
import type { AxiosResponse } from "axios";
|
||
|
import type {
|
||
|
ProtocolDecisionViewModel,
|
||
|
SyncProtocolDecisionViewModel,
|
||
|
} from "../../viewmodels/admin/protocolDecision.models";
|
||
|
import { useProtocolStore } from "./protocol";
|
||
|
|
||
|
export const useProtocolDecisionStore = defineStore("protocolDecision", {
|
||
|
state: () => {
|
||
|
return {
|
||
|
decision: [] as Array<ProtocolDecisionViewModel>,
|
||
|
loading: "loading" as "loading" | "fetched" | "failed",
|
||
|
};
|
||
|
},
|
||
|
actions: {
|
||
|
fetchProtocolDecision() {
|
||
|
const protocolId = useProtocolStore().activeProtocol;
|
||
|
this.loading = "loading";
|
||
|
http
|
||
|
.get(`/admin/protocol/${protocolId}/decisions`)
|
||
|
.then((result) => {
|
||
|
this.decision = result.data;
|
||
|
this.loading = "fetched";
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.loading = "failed";
|
||
|
});
|
||
|
},
|
||
|
async synchronizeActiveProtocolDecision(
|
||
|
decision: Array<SyncProtocolDecisionViewModel>
|
||
|
): Promise<AxiosResponse<any, any>> {
|
||
|
const protocolId = useProtocolStore().activeProtocol;
|
||
|
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/decisions`, {
|
||
|
decision: decision,
|
||
|
});
|
||
|
this.fetchProtocolDecision();
|
||
|
return result;
|
||
|
},
|
||
|
},
|
||
|
});
|