45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { http } from "@/serverCom";
|
|
import type { AxiosResponse } from "axios";
|
|
import type {
|
|
ProtocolVotingViewModel,
|
|
SyncProtocolVotingViewModel,
|
|
} from "../../viewmodels/admin/protocolVoting.models";
|
|
import { useProtocolStore } from "./protocol";
|
|
import cloneDeep from "lodash.clonedeep";
|
|
import isEqual from "lodash.isEqual";
|
|
import difference from "lodash.difference";
|
|
|
|
export const useProtocolVotingStore = defineStore("protocolVoting", {
|
|
state: () => {
|
|
return {
|
|
voting: [] as Array<ProtocolVotingViewModel>,
|
|
loading: "loading" as "loading" | "fetched" | "failed",
|
|
};
|
|
},
|
|
actions: {
|
|
fetchProtocolVoting() {
|
|
const protocolId = useProtocolStore().activeProtocol;
|
|
this.loading = "loading";
|
|
http
|
|
.get(`/admin/protocol/${protocolId}/votings`)
|
|
.then((result) => {
|
|
this.voting = result.data;
|
|
this.loading = "fetched";
|
|
})
|
|
.catch((err) => {
|
|
this.loading = "failed";
|
|
});
|
|
},
|
|
async synchronizeActiveProtocolVoting(
|
|
voting: Array<SyncProtocolVotingViewModel>
|
|
): Promise<AxiosResponse<any, any>> {
|
|
const protocolId = useProtocolStore().activeProtocol;
|
|
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/votings`, {
|
|
voting: voting,
|
|
});
|
|
this.fetchProtocolVoting();
|
|
return result;
|
|
},
|
|
},
|
|
});
|