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 {
|
||
|
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;
|
||
|
},
|
||
|
},
|
||
|
});
|