2024-09-17 16:44:02 +02:00
|
|
|
import { defineStore } from "pinia";
|
|
|
|
import type { CreateMemberViewModel, UpdateMemberViewModel } from "@/viewmodels/admin/member.models";
|
|
|
|
import { http } from "@/serverCom";
|
|
|
|
import type { AxiosResponse } from "axios";
|
|
|
|
import type { MemberViewModel } from "@/viewmodels/admin/member.models";
|
|
|
|
import { useMemberStore } from "./member";
|
|
|
|
import type {
|
|
|
|
CreateCommunicationViewModel,
|
|
|
|
CommunicationViewModel,
|
|
|
|
UpdateCommunicationViewModel,
|
|
|
|
} from "@/viewmodels/admin/communication.models";
|
|
|
|
|
|
|
|
export const useCommunicationStore = defineStore("communication", {
|
|
|
|
state: () => {
|
|
|
|
return {
|
|
|
|
communications: [] as Array<CommunicationViewModel>,
|
|
|
|
loading: "loading" as "loading" | "fetched" | "failed",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
fetchCommunicationsForMember() {
|
|
|
|
const memberId = useMemberStore().activeMember;
|
|
|
|
this.loading = "loading";
|
|
|
|
http
|
|
|
|
.get(`/admin/member/${memberId}/communications`)
|
|
|
|
.then((result) => {
|
|
|
|
this.communications = result.data;
|
|
|
|
this.loading = "fetched";
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.loading = "failed";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchCommunicationById(id: number) {
|
|
|
|
const memberId = useMemberStore().activeMember;
|
|
|
|
return http.get(`/admin/member/${memberId}/communication/${id}`);
|
|
|
|
},
|
|
|
|
async createCommunication(communication: CreateCommunicationViewModel): Promise<AxiosResponse<any, any>> {
|
|
|
|
const memberId = useMemberStore().activeMember;
|
|
|
|
const result = await http.post(`/admin/member/${memberId}/communication`, {
|
|
|
|
preferred: communication.preferred,
|
|
|
|
mobile: communication.mobile,
|
|
|
|
email: communication.email,
|
|
|
|
city: communication.city,
|
|
|
|
street: communication.street,
|
|
|
|
streetNumber: communication.streetNumber,
|
|
|
|
streetNumberAddition: communication.streetNumberAddition,
|
|
|
|
typeId: communication.typeId,
|
2024-09-27 14:55:49 +02:00
|
|
|
isNewsletterMain: communication.isNewsletterMain,
|
2024-11-27 10:07:46 +01:00
|
|
|
isSMSAlarming: communication.isSMSAlarming,
|
2024-09-17 16:44:02 +02:00
|
|
|
});
|
|
|
|
this.fetchCommunicationsForMember();
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
async updateCommunication(communication: UpdateCommunicationViewModel): Promise<AxiosResponse<any, any>> {
|
|
|
|
const memberId = useMemberStore().activeMember;
|
|
|
|
const result = await http.patch(`/admin/member/${memberId}/communication/${communication.id}`, {
|
|
|
|
preferred: communication.preferred,
|
|
|
|
mobile: communication.mobile,
|
|
|
|
email: communication.email,
|
|
|
|
city: communication.city,
|
|
|
|
street: communication.street,
|
|
|
|
streetNumber: communication.streetNumber,
|
|
|
|
streetNumberAddition: communication.streetNumberAddition,
|
2024-09-27 14:55:49 +02:00
|
|
|
isNewsletterMain: communication.isNewsletterMain,
|
2024-11-27 10:07:46 +01:00
|
|
|
isSMSAlarming: communication.isSMSAlarming,
|
2024-09-17 16:44:02 +02:00
|
|
|
});
|
|
|
|
this.fetchCommunicationsForMember();
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
async deleteCommunication(communication: number): Promise<AxiosResponse<any, any>> {
|
|
|
|
const memberId = useMemberStore().activeMember;
|
|
|
|
const result = await http.delete(`/admin/member/${memberId}/communication/${communication}`);
|
|
|
|
this.fetchCommunicationsForMember();
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|