4702 rename calendareventattendee to calendareventparticipant (#4761)

Closes #4702
This commit is contained in:
bosiraphael
2024-04-04 14:00:10 +02:00
committed by GitHub
parent 357882c395
commit 85caed3463
36 changed files with 305 additions and 330 deletions

View File

@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
import { CalendarEventAttendeeService } from 'src/modules/calendar/services/calendar-event-attendee/calendar-event-attendee.service';
import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service';
import { AddPersonIdAndWorkspaceMemberIdModule } from 'src/modules/connected-account/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.module';
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
@ -12,7 +12,7 @@ import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person
ObjectMetadataRepositoryModule.forFeature([PersonObjectMetadata]),
AddPersonIdAndWorkspaceMemberIdModule,
],
providers: [CalendarEventAttendeeService],
exports: [CalendarEventAttendeeService],
providers: [CalendarEventParticipantService],
exports: [CalendarEventParticipantService],
})
export class CalendarEventAttendeeModule {}
export class CalendarEventParticipantModule {}

View File

@ -8,13 +8,13 @@ import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
import {
CalendarEventAttendee,
CalendarEventAttendeeWithId,
CalendarEventParticipant,
CalendarEventParticipantWithId,
} from 'src/modules/calendar/types/calendar-event';
import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/connected-account/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service';
@Injectable()
export class CalendarEventAttendeeService {
export class CalendarEventParticipantService {
constructor(
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
@InjectObjectMetadataRepository(PersonObjectMetadata)
@ -22,36 +22,38 @@ export class CalendarEventAttendeeService {
private readonly addPersonIdAndWorkspaceMemberIdService: AddPersonIdAndWorkspaceMemberIdService,
) {}
public async updateCalendarEventAttendeesAfterContactCreation(
attendees: CalendarEventAttendeeWithId[],
public async updateCalendarEventParticipantsAfterContactCreation(
participants: CalendarEventParticipantWithId[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
if (!attendees) return;
if (!participants) return;
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
const handles = attendees.map((attendee) => attendee.handle);
const handles = participants.map((participant) => participant.handle);
const attendeePersonIds = await this.personRepository.getByEmails(
const participantPersonIds = await this.personRepository.getByEmails(
handles,
workspaceId,
transactionManager,
);
const calendarEventAttendeesToUpdate = attendees.map((attendee) => ({
id: attendee.id,
personId: attendeePersonIds.find(
(e: { id: string; email: string }) => e.email === attendee.handle,
)?.id,
}));
const calendarEventParticipantsToUpdate = participants.map(
(participant) => ({
id: participant.id,
personId: participantPersonIds.find(
(e: { id: string; email: string }) => e.email === participant.handle,
)?.id,
}),
);
if (calendarEventAttendeesToUpdate.length === 0) return;
if (calendarEventParticipantsToUpdate.length === 0) return;
const { flattenedValues, valuesString } =
getFlattenedValuesAndValuesStringForBatchRawQuery(
calendarEventAttendeesToUpdate,
calendarEventParticipantsToUpdate,
{
id: 'uuid',
personId: 'uuid',
@ -59,50 +61,50 @@ export class CalendarEventAttendeeService {
);
await this.workspaceDataSourceService.executeRawQuery(
`UPDATE ${dataSourceSchema}."calendarEventAttendee" AS "calendarEventAttendee" SET "personId" = "data"."personId"
`UPDATE ${dataSourceSchema}."calendarEventParticipant" AS "calendarEventParticipant" SET "personId" = "data"."personId"
FROM (VALUES ${valuesString}) AS "data"("id", "personId")
WHERE "calendarEventAttendee"."id" = "data"."id"`,
WHERE "calendarEventParticipant"."id" = "data"."id"`,
flattenedValues,
workspaceId,
transactionManager,
);
}
public async saveCalendarEventAttendees(
calendarEventAttendees: CalendarEventAttendee[],
public async saveCalendarEventParticipants(
calendarEventParticipants: CalendarEventParticipant[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
if (calendarEventAttendees.length === 0) {
if (calendarEventParticipants.length === 0) {
return;
}
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
const calendarEventAttendeesToSave =
const calendarEventParticipantsToSave =
await this.addPersonIdAndWorkspaceMemberIdService.addPersonIdAndWorkspaceMemberId(
calendarEventAttendees,
calendarEventParticipants,
workspaceId,
transactionManager,
);
const { flattenedValues, valuesString } =
getFlattenedValuesAndValuesStringForBatchRawQuery(
calendarEventAttendeesToSave,
calendarEventParticipantsToSave,
{
calendarEventId: 'uuid',
handle: 'text',
displayName: 'text',
isOrganizer: 'boolean',
responseStatus: `${dataSourceSchema}."calendarEventAttendee_responsestatus_enum"`,
responseStatus: `${dataSourceSchema}."calendarEventParticipant_responsestatus_enum"`,
personId: 'uuid',
workspaceMemberId: 'uuid',
},
);
await this.workspaceDataSourceService.executeRawQuery(
`INSERT INTO ${dataSourceSchema}."calendarEventAttendee" ("calendarEventId", "handle", "displayName", "isOrganizer", "responseStatus", "personId", "workspaceMemberId") VALUES ${valuesString}`,
`INSERT INTO ${dataSourceSchema}."calendarEventParticipant" ("calendarEventId", "handle", "displayName", "isOrganizer", "responseStatus", "personId", "workspaceMemberId") VALUES ${valuesString}`,
flattenedValues,
workspaceId,
transactionManager,

View File

@ -4,12 +4,12 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
import { CalendarEventAttendeeModule } from 'src/modules/calendar/services/calendar-event-attendee/calendar-event-attendee.module';
import { CalendarEventParticipantModule } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.module';
import { GoogleCalendarFullSyncService } from 'src/modules/calendar/services/google-calendar-full-sync.service';
import { CalendarProvidersModule } from 'src/modules/calendar/services/providers/calendar-providers.module';
import { CalendarChannelEventAssociationObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.object-metadata';
import { CalendarChannelObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel.object-metadata';
import { CalendarEventAttendeeObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-attendee.object-metadata';
import { CalendarEventParticipantObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-participant.object-metadata';
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
import { ConnectedAccountObjectMetadata } from 'src/modules/connected-account/standard-objects/connected-account.object-metadata';
@ -24,12 +24,12 @@ import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/stan
CalendarEventObjectMetadata,
CalendarChannelObjectMetadata,
CalendarChannelEventAssociationObjectMetadata,
CalendarEventAttendeeObjectMetadata,
CalendarEventParticipantObjectMetadata,
BlocklistObjectMetadata,
PersonObjectMetadata,
WorkspaceMemberObjectMetadata,
]),
CalendarEventAttendeeModule,
CalendarEventParticipantModule,
TypeOrmModule.forFeature([FeatureFlagEntity], 'core'),
WorkspaceDataSourceModule,
],

View File

@ -20,15 +20,15 @@ import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/work
import { CalendarEventRepository } from 'src/modules/calendar/repositories/calendar-event.repository';
import { formatGoogleCalendarEvent } from 'src/modules/calendar/utils/format-google-calendar-event.util';
import { GoogleCalendarFullSyncJobData } from 'src/modules/calendar/jobs/google-calendar-full-sync.job';
import { CalendarEventAttendeeRepository } from 'src/modules/calendar/repositories/calendar-event-attendee.repository';
import { CalendarEventParticipantRepository } from 'src/modules/calendar/repositories/calendar-event-participant.repository';
import { ConnectedAccountObjectMetadata } from 'src/modules/connected-account/standard-objects/connected-account.object-metadata';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
import { CalendarChannelObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel.object-metadata';
import { CalendarChannelEventAssociationObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.object-metadata';
import { CalendarEventAttendeeObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-attendee.object-metadata';
import { CalendarEventParticipantObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-participant.object-metadata';
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
import { CalendarEventAttendeeService } from 'src/modules/calendar/services/calendar-event-attendee/calendar-event-attendee.service';
import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service';
@Injectable()
export class GoogleCalendarFullSyncService {
@ -48,15 +48,15 @@ export class GoogleCalendarFullSyncService {
CalendarChannelEventAssociationObjectMetadata,
)
private readonly calendarChannelEventAssociationRepository: CalendarChannelEventAssociationRepository,
@InjectObjectMetadataRepository(CalendarEventAttendeeObjectMetadata)
private readonly calendarEventAttendeesRepository: CalendarEventAttendeeRepository,
@InjectObjectMetadataRepository(CalendarEventParticipantObjectMetadata)
private readonly calendarEventParticipantsRepository: CalendarEventParticipantRepository,
@InjectObjectMetadataRepository(BlocklistObjectMetadata)
private readonly blocklistRepository: BlocklistRepository,
@InjectRepository(FeatureFlagEntity, 'core')
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
private readonly eventEmitter: EventEmitter2,
private readonly calendarEventAttendeesService: CalendarEventAttendeeService,
private readonly calendarEventParticipantsService: CalendarEventParticipantService,
) {}
public async startGoogleCalendarFullSync(
@ -197,10 +197,12 @@ export class GoogleCalendarFullSyncService {
}),
);
const attendeesToSave = eventsToSave.flatMap((event) => event.attendees);
const participantsToSave = eventsToSave.flatMap(
(event) => event.participants,
);
const attendeesToUpdate = eventsToUpdate.flatMap(
(event) => event.attendees,
const participantsToUpdate = eventsToUpdate.flatMap(
(event) => event.participants,
);
const iCalUIDCalendarEventIdMap =
@ -267,8 +269,8 @@ export class GoogleCalendarFullSyncService {
startTime = Date.now();
await this.calendarEventAttendeesService.saveCalendarEventAttendees(
attendeesToSave,
await this.calendarEventParticipantsService.saveCalendarEventParticipants(
participantsToSave,
workspaceId,
transactionManager,
);
@ -276,15 +278,15 @@ export class GoogleCalendarFullSyncService {
endTime = Date.now();
this.logger.log(
`google calendar full-sync for workspace ${workspaceId} and account ${connectedAccountId}: saving attendees in ${
`google calendar full-sync for workspace ${workspaceId} and account ${connectedAccountId}: saving participants in ${
endTime - startTime
}ms.`,
);
startTime = Date.now();
await this.calendarEventAttendeesRepository.updateCalendarEventAttendees(
attendeesToUpdate,
await this.calendarEventParticipantsRepository.updateCalendarEventParticipants(
participantsToUpdate,
iCalUIDCalendarEventIdMap,
workspaceId,
transactionManager,
@ -293,14 +295,14 @@ export class GoogleCalendarFullSyncService {
endTime = Date.now();
this.logger.log(
`google calendar full-sync for workspace ${workspaceId} and account ${connectedAccountId}: updating attendees in ${
`google calendar full-sync for workspace ${workspaceId} and account ${connectedAccountId}: updating participants in ${
endTime - startTime
}ms.`,
);
});
if (calendarChannel.isContactAutoCreationEnabled) {
const contactsToCreate = attendeesToSave;
const contactsToCreate = participantsToSave;
this.eventEmitter.emit(`createContacts`, {
workspaceId,