Use same lock values as mobile clients
[ProtonMail-WebClient.git] / packages / shared / lib / calendar / getMemberWithAdmin.ts
blobaba6df7bfe51286a1cc3f5d0fa8ac475e934016e
1 import { hasBit } from '../helpers/bitset';
2 import type { Address as AddressInterface } from '../interfaces';
3 import type { CalendarMember as MemberInterface } from '../interfaces/calendar';
4 import { CALENDAR_PERMISSIONS } from './constants';
6 export const getMemberAddressWithAdminPermissions = (Members: MemberInterface[], Addresses: AddressInterface[]) => {
7     const Member = Members.find(({ Email: MemberEmail, Permissions }) => {
8         return hasBit(Permissions, CALENDAR_PERMISSIONS.ADMIN) && Addresses.find(({ Email }) => MemberEmail === Email);
9     });
10     if (!Member) {
11         throw new Error('Member with admin permission not found');
12     }
13     const Address = Addresses.find(({ Email }) => Member.Email === Email);
14     if (!Address) {
15         throw new Error('Address for member not found');
16     }
17     return {
18         Member,
19         Address,
20     };