4398 decouple contacts and companies creation from messages import (#4590)
* emit event * create queue and listener * filter participants with role 'from' * create job * Add job to job module * Refactoring * Refactor contact creation in CreateCompanyAndContactService * update job * wip * add getByHandlesWithoutPersonIdAndWorkspaceMemberId to calendar event attendee repository * refactoring * refactoring * Revert "refactoring" This reverts commit e5434f0b871e45447227aa8d55ba5af381c3ff1c. * fix nest imports * add await * fix contact creation condition * emit contact creation event after calendar-full-sync * add await * add missing transactionManager * calendar event attendees personId update is working * messageParticipant and calendarEventAttendee update is working as intended * rename module * fix lodash import * add test * update package.json
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
import { Contacts } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
|
||||
import { getUniqueContactsAndHandles } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/get-unique-contacts-and-handles.util';
|
||||
|
||||
describe('getUniqueContactsAndHandles', () => {
|
||||
it('should return empty arrays when contacts is empty', () => {
|
||||
const contacts: Contacts = [];
|
||||
const result = getUniqueContactsAndHandles(contacts);
|
||||
|
||||
expect(result.uniqueContacts).toEqual([]);
|
||||
expect(result.uniqueHandles).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return unique contacts and handles', () => {
|
||||
const contacts: Contacts = [
|
||||
{ handle: 'john@twenty.com', displayName: 'John Doe' },
|
||||
{ handle: 'john@twenty.com', displayName: 'John Doe' },
|
||||
{ handle: 'jane@twenty.com', displayName: 'Jane Smith' },
|
||||
{ handle: 'jane@twenty.com', displayName: 'Jane Smith' },
|
||||
{ handle: 'jane@twenty.com', displayName: 'Jane Smith' },
|
||||
];
|
||||
const result = getUniqueContactsAndHandles(contacts);
|
||||
|
||||
expect(result.uniqueContacts).toEqual([
|
||||
{ handle: 'john@twenty.com', displayName: 'John Doe' },
|
||||
{ handle: 'jane@twenty.com', displayName: 'Jane Smith' },
|
||||
]);
|
||||
expect(result.uniqueHandles).toEqual([
|
||||
'john@twenty.com',
|
||||
'jane@twenty.com',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,27 @@
|
||||
import { getDomainNameFromHandle } from 'src/modules/messaging/utils/get-domain-name-from-handle.util';
|
||||
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { Contacts } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
|
||||
|
||||
export function filterOutContactsFromCompanyOrWorkspace(
|
||||
contacts: Contacts,
|
||||
selfHandle: string,
|
||||
workspaceMembers: ObjectRecord<WorkspaceMemberObjectMetadata>[],
|
||||
): Contacts {
|
||||
const selfDomainName = getDomainNameFromHandle(selfHandle);
|
||||
|
||||
const workspaceMembersMap = workspaceMembers.reduce(
|
||||
(map, workspaceMember) => {
|
||||
map[workspaceMember.userEmail] = true;
|
||||
|
||||
return map;
|
||||
},
|
||||
new Map<string, boolean>(),
|
||||
);
|
||||
|
||||
return contacts.filter(
|
||||
(contact) =>
|
||||
getDomainNameFromHandle(contact.handle) !== selfDomainName &&
|
||||
!workspaceMembersMap[contact.handle],
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
import uniq from 'lodash.uniq';
|
||||
import uniqBy from 'lodash.uniqby';
|
||||
|
||||
import { Contacts } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
|
||||
|
||||
export function getUniqueContactsAndHandles(contacts: Contacts): {
|
||||
uniqueContacts: Contacts;
|
||||
uniqueHandles: string[];
|
||||
} {
|
||||
if (contacts.length === 0) {
|
||||
return { uniqueContacts: [], uniqueHandles: [] };
|
||||
}
|
||||
|
||||
const uniqueHandles = uniq(contacts.map((participant) => participant.handle));
|
||||
|
||||
const uniqueContacts = uniqBy(contacts, 'handle');
|
||||
|
||||
return { uniqueContacts, uniqueHandles };
|
||||
}
|
||||
Reference in New Issue
Block a user