1 import type { Address as AddressInterface } from '../interfaces';
2 import type { CalendarMember as MemberInterface } from '../interfaces/calendar';
4 export const getMemberAndAddress = (
5 Addresses: AddressInterface[] = [],
6 Members: MemberInterface[] = [],
8 ): [MemberInterface, AddressInterface] => {
10 throw new Error('No members');
12 if (!Addresses.length) {
13 throw new Error('No addresses');
16 // First try to find self by author to use the same address.
17 const selfAddress = Addresses.find((Address) => Address.Email === Author);
18 const selfMember = selfAddress ? Members.find((Member) => Member.Email === selfAddress.Email) : undefined;
20 if (selfMember && selfAddress) {
21 return [selfMember, selfAddress];
24 // Otherwise just use the first member. It is assumed the list of members only contain yourself.
25 const [defaultMember] = Members;
27 const Address = Addresses.find(({ Email }) => defaultMember.Email === Email);
29 throw new Error('Self as member not found');
31 return [defaultMember, Address];