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:
bosiraphael
2024-03-22 18:44:14 +01:00
committed by GitHub
parent 1a763263c9
commit 96cad2accd
29 changed files with 580 additions and 271 deletions

View File

@ -1,5 +1,6 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Repository } from 'typeorm';
@ -53,6 +54,7 @@ export class GoogleCalendarFullSyncService {
@InjectRepository(FeatureFlagEntity, 'core')
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
private readonly eventEmitter: EventEmitter2,
) {}
public async startGoogleCalendarFullSync(
@ -294,6 +296,16 @@ export class GoogleCalendarFullSyncService {
}ms.`,
);
});
if (calendarChannel.isContactAutoCreationEnabled) {
const contactsToCreate = attendeesToSave;
this.eventEmitter.emit(`createContacts`, {
workspaceId,
connectedAccountHandle: connectedAccount.handle,
contactsToCreate,
});
}
} catch (error) {
this.logger.error(
`Error during google calendar full-sync for workspace ${workspaceId} and account ${connectedAccountId}: ${error.message}`,