protocol data stores

This commit is contained in:
Julian Krauser 2024-10-13 15:47:52 +02:00
parent 8664836a20
commit 41b300fb72
15 changed files with 259 additions and 31 deletions

View file

@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import type { CreateProtocolViewModel, UpdateProtocolViewModel } from "@/viewmodels/admin/protocol.models";
import type { CreateProtocolViewModel, SyncProtocolViewModel } from "@/viewmodels/admin/protocol.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type { ProtocolViewModel } from "@/viewmodels/admin/protocol.models";
@ -64,18 +64,16 @@ export const useProtocolStore = defineStore("protocol", {
this.fetchProtocols();
return result;
},
async updateActiveProtocol(protocol: UpdateProtocolViewModel): Promise<AxiosResponse<any, any>> {
async synchronizeActiveProtocol(protocol: SyncProtocolViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/protocol/${protocol.id}`, {
title: protocol.title,
date: protocol.date,
starttime: protocol.starttime,
endtime: protocol.endtime,
summary: protocol.summary,
});
this.fetchProtocols();
return result;
},
async deleteProtocol(protocol: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/protocol/${protocol}`);
this.fetchProtocols();
return result;
},
},
});

View file

@ -0,0 +1,42 @@
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;
},
},
});

View file

@ -0,0 +1,42 @@
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;
},
},
});

View file

@ -0,0 +1,42 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
ProtocolPresenceViewModel,
SyncProtocolPresenceViewModel,
} from "../../viewmodels/admin/protocolPresence.models";
import { useProtocolStore } from "./protocol";
export const useProtocolPresenceStore = defineStore("protocolPresence", {
state: () => {
return {
presence: [] as Array<ProtocolPresenceViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchProtocolPresence() {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/presence`)
.then((result) => {
this.presence = result.data;
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async synchronizeActiveProtocolPresence(
presence: Array<SyncProtocolPresenceViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/presence`, {
presence: presence,
});
this.fetchProtocolPresence();
return result;
},
},
});

View file

@ -0,0 +1,42 @@
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";
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;
},
},
});