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

@ -5,25 +5,25 @@ import differenceWith from 'lodash.differencewith';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
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 { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
import {
CalendarEventAttendee,
CalendarEventAttendeeWithId,
CalendarEventParticipant,
CalendarEventParticipantWithId,
} from 'src/modules/calendar/types/calendar-event';
@Injectable()
export class CalendarEventAttendeeRepository {
export class CalendarEventParticipantRepository {
constructor(
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
) {}
public async getByIds(
calendarEventAttendeeIds: string[],
calendarEventParticipantIds: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarEventAttendeeObjectMetadata>[]> {
if (calendarEventAttendeeIds.length === 0) {
): Promise<ObjectRecord<CalendarEventParticipantObjectMetadata>[]> {
if (calendarEventParticipantIds.length === 0) {
return [];
}
@ -31,8 +31,8 @@ export class CalendarEventAttendeeRepository {
this.workspaceDataSourceService.getSchemaName(workspaceId);
return await this.workspaceDataSourceService.executeRawQuery(
`SELECT * FROM ${dataSourceSchema}."calendarEventAttendee" WHERE "id" = ANY($1)`,
[calendarEventAttendeeIds],
`SELECT * FROM ${dataSourceSchema}."calendarEventParticipant" WHERE "id" = ANY($1)`,
[calendarEventParticipantIds],
workspaceId,
transactionManager,
);
@ -42,7 +42,7 @@ export class CalendarEventAttendeeRepository {
calendarEventIds: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarEventAttendeeObjectMetadata>[]> {
): Promise<ObjectRecord<CalendarEventParticipantObjectMetadata>[]> {
if (calendarEventIds.length === 0) {
return [];
}
@ -51,7 +51,7 @@ export class CalendarEventAttendeeRepository {
this.workspaceDataSourceService.getSchemaName(workspaceId);
return await this.workspaceDataSourceService.executeRawQuery(
`SELECT * FROM ${dataSourceSchema}."calendarEventAttendee" WHERE "calendarEventId" = ANY($1)`,
`SELECT * FROM ${dataSourceSchema}."calendarEventParticipant" WHERE "calendarEventId" = ANY($1)`,
[calendarEventIds],
workspaceId,
transactionManager,
@ -59,11 +59,11 @@ export class CalendarEventAttendeeRepository {
}
public async deleteByIds(
calendarEventAttendeeIds: string[],
calendarEventParticipantIds: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
if (calendarEventAttendeeIds.length === 0) {
if (calendarEventParticipantIds.length === 0) {
return;
}
@ -71,20 +71,20 @@ export class CalendarEventAttendeeRepository {
this.workspaceDataSourceService.getSchemaName(workspaceId);
await this.workspaceDataSourceService.executeRawQuery(
`DELETE FROM ${dataSourceSchema}."calendarEventAttendee" WHERE "id" = ANY($1)`,
[calendarEventAttendeeIds],
`DELETE FROM ${dataSourceSchema}."calendarEventParticipant" WHERE "id" = ANY($1)`,
[calendarEventParticipantIds],
workspaceId,
transactionManager,
);
}
public async updateCalendarEventAttendees(
calendarEventAttendees: CalendarEventAttendee[],
public async updateCalendarEventParticipants(
calendarEventParticipants: CalendarEventParticipant[],
iCalUIDCalendarEventIdMap: Map<string, string>,
workspaceId: string,
transactionManager?: EntityManager,
): Promise<void> {
if (calendarEventAttendees.length === 0) {
if (calendarEventParticipants.length === 0) {
return;
}
@ -93,33 +93,36 @@ export class CalendarEventAttendeeRepository {
const calendarEventIds = Array.from(iCalUIDCalendarEventIdMap.values());
const existingCalendarEventAttendees = await this.getByCalendarEventIds(
const existingCalendarEventParticipants = await this.getByCalendarEventIds(
calendarEventIds,
workspaceId,
transactionManager,
);
const calendarEventAttendeesToDelete = differenceWith(
existingCalendarEventAttendees,
calendarEventAttendees,
(existingCalendarEventAttendee, calendarEventAttendee) =>
existingCalendarEventAttendee.handle === calendarEventAttendee.handle,
const calendarEventParticipantsToDelete = differenceWith(
existingCalendarEventParticipants,
calendarEventParticipants,
(existingCalendarEventParticipant, calendarEventParticipant) =>
existingCalendarEventParticipant.handle ===
calendarEventParticipant.handle,
);
await this.deleteByIds(
calendarEventAttendeesToDelete.map(
(calendarEventAttendee) => calendarEventAttendee.id,
calendarEventParticipantsToDelete.map(
(calendarEventParticipant) => calendarEventParticipant.id,
),
workspaceId,
transactionManager,
);
const values = calendarEventAttendees.map((calendarEventAttendee) => ({
...calendarEventAttendee,
calendarEventId: iCalUIDCalendarEventIdMap.get(
calendarEventAttendee.iCalUID,
),
}));
const values = calendarEventParticipants.map(
(calendarEventParticipant) => ({
...calendarEventParticipant,
calendarEventId: iCalUIDCalendarEventIdMap.get(
calendarEventParticipant.iCalUID,
),
}),
);
const { flattenedValues, valuesString } =
getFlattenedValuesAndValuesStringForBatchRawQuery(values, {
@ -127,17 +130,17 @@ export class CalendarEventAttendeeRepository {
handle: 'text',
displayName: 'text',
isOrganizer: 'boolean',
responseStatus: `${dataSourceSchema}."calendarEventAttendee_responsestatus_enum"`,
responseStatus: `${dataSourceSchema}."calendarEventParticipant_responsestatus_enum"`,
});
await this.workspaceDataSourceService.executeRawQuery(
`UPDATE ${dataSourceSchema}."calendarEventAttendee" AS "calendarEventAttendee"
`UPDATE ${dataSourceSchema}."calendarEventParticipant" AS "calendarEventParticipant"
SET "displayName" = "newValues"."displayName",
"isOrganizer" = "newValues"."isOrganizer",
"responseStatus" = "newValues"."responseStatus"
FROM (VALUES ${valuesString}) AS "newValues"("calendarEventId", "handle", "displayName", "isOrganizer", "responseStatus")
WHERE "calendarEventAttendee"."handle" = "newValues"."handle"
AND "calendarEventAttendee"."calendarEventId" = "newValues"."calendarEventId"`,
WHERE "calendarEventParticipant"."handle" = "newValues"."handle"
AND "calendarEventParticipant"."calendarEventId" = "newValues"."calendarEventId"`,
flattenedValues,
workspaceId,
transactionManager,
@ -147,7 +150,7 @@ export class CalendarEventAttendeeRepository {
public async getWithoutPersonIdAndWorkspaceMemberId(
workspaceId: string,
transactionManager?: EntityManager,
): Promise<CalendarEventAttendeeWithId[]> {
): Promise<CalendarEventParticipantWithId[]> {
if (!workspaceId) {
throw new Error('WorkspaceId is required');
}
@ -155,17 +158,17 @@ export class CalendarEventAttendeeRepository {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
const calendarEventAttendees: CalendarEventAttendeeWithId[] =
const calendarEventParticipants: CalendarEventParticipantWithId[] =
await this.workspaceDataSourceService.executeRawQuery(
`SELECT "calendarEventAttendee".*
FROM ${dataSourceSchema}."calendarEventAttendee" AS "calendarEventAttendee"
WHERE "calendarEventAttendee"."personId" IS NULL
AND "calendarEventAttendee"."workspaceMemberId" IS NULL`,
`SELECT "calendarEventParticipant".*
FROM ${dataSourceSchema}."calendarEventParticipant" AS "calendarEventParticipant"
WHERE "calendarEventParticipant"."personId" IS NULL
AND "calendarEventParticipant"."workspaceMemberId" IS NULL`,
[],
workspaceId,
transactionManager,
);
return calendarEventAttendees;
return calendarEventParticipants;
}
}

View File

@ -7,7 +7,7 @@ import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metada
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
import { CalendarEvent } from 'src/modules/calendar/types/calendar-event';
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';
@Injectable()
export class CalendarEventRepository {
@ -60,7 +60,7 @@ export class CalendarEventRepository {
offset: number,
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarEventAttendeeObjectMetadata>[]> {
): Promise<ObjectRecord<CalendarEventParticipantObjectMetadata>[]> {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);