contact/company creations errors (#11540)

Seeing a couple of issues related to company creations in logs, I
suspect this to be the root cause

This should help a lot in all the support we have to do on email
synchronisation
This commit is contained in:
Guillim
2025-04-11 15:19:03 +02:00
committed by GitHub
parent 9da5cca82a
commit 2a8defe262

View File

@ -9,16 +9,20 @@ export function filterOutSelfAndContactsFromCompanyOrWorkspace(
connectedAccount: ConnectedAccountWorkspaceEntity,
workspaceMembers: WorkspaceMemberWorkspaceEntity[],
): Contact[] {
const selfDomainName = getDomainNameFromHandle(connectedAccount.handle);
const selfDomainName = getDomainNameFromHandle(
connectedAccount.handle,
).toLowerCase();
const allHandles = [
connectedAccount.handle,
...(connectedAccount.handleAliases?.split(',') || []),
connectedAccount.handle.toLowerCase(),
...(connectedAccount.handleAliases?.split(',') || []).map((handle) =>
handle.toLowerCase(),
),
];
const workspaceMembersMap = workspaceMembers.reduce(
(map, workspaceMember) => {
map[workspaceMember.userEmail] = true;
map[workspaceMember.userEmail.toLowerCase()] = true;
return map;
},
@ -26,13 +30,13 @@ export function filterOutSelfAndContactsFromCompanyOrWorkspace(
);
const isDifferentDomain = (contact: Contact, selfDomainName: string) =>
getDomainNameFromHandle(contact.handle) !== selfDomainName;
getDomainNameFromHandle(contact.handle).toLowerCase() !== selfDomainName;
return contacts.filter(
(contact) =>
(isDifferentDomain(contact, selfDomainName) ||
!isWorkDomain(selfDomainName)) &&
!workspaceMembersMap[contact.handle] &&
!allHandles.includes(contact.handle),
!workspaceMembersMap[contact.handle.toLowerCase()] &&
!allHandles.includes(contact.handle.toLowerCase()),
);
}