2024-10-13 15:47:52 +02:00
|
|
|
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";
|
2024-10-15 16:24:29 +02:00
|
|
|
import cloneDeep from "lodash.clonedeep";
|
|
|
|
import isEqual from "lodash.isEqual";
|
|
|
|
import difference from "lodash.difference";
|
2024-10-13 15:47:52 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|