Fix duplicated calendar events (#5209)

Fix duplicated calendar events when two workspace members participate to
the same event.
This commit is contained in:
bosiraphael
2024-04-29 15:23:40 +02:00
committed by GitHub
parent 9809298753
commit 6cafd25c97
3 changed files with 343 additions and 275 deletions

View File

@ -162,7 +162,6 @@ export class CalendarEventParticipantRepository {
public async updateCalendarEventParticipantsAndReturnNewOnes(
calendarEventParticipants: CalendarEventParticipant[],
iCalUIDCalendarEventIdMap: Map<string, string>,
workspaceId: string,
transactionManager?: EntityManager,
): Promise<CalendarEventParticipant[]> {
@ -173,10 +172,10 @@ export class CalendarEventParticipantRepository {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
const calendarEventIds = Array.from(iCalUIDCalendarEventIdMap.values());
const existingCalendarEventParticipants = await this.getByCalendarEventIds(
calendarEventIds,
calendarEventParticipants.map(
(calendarEventParticipant) => calendarEventParticipant.calendarEventId,
),
workspaceId,
transactionManager,
);
@ -205,23 +204,17 @@ export class CalendarEventParticipantRepository {
transactionManager,
);
const values = calendarEventParticipants.map(
(calendarEventParticipant) => ({
...calendarEventParticipant,
calendarEventId: iCalUIDCalendarEventIdMap.get(
calendarEventParticipant.iCalUID,
),
}),
);
const { flattenedValues, valuesString } =
getFlattenedValuesAndValuesStringForBatchRawQuery(values, {
calendarEventId: 'uuid',
handle: 'text',
displayName: 'text',
isOrganizer: 'boolean',
responseStatus: `${dataSourceSchema}."calendarEventParticipant_responsestatus_enum"`,
});
getFlattenedValuesAndValuesStringForBatchRawQuery(
calendarEventParticipants,
{
calendarEventId: 'uuid',
handle: 'text',
displayName: 'text',
isOrganizer: 'boolean',
responseStatus: `${dataSourceSchema}."calendarEventParticipant_responsestatus_enum"`,
},
);
await this.workspaceDataSourceService.executeRawQuery(
`UPDATE ${dataSourceSchema}."calendarEventParticipant" AS "calendarEventParticipant"

View File

@ -35,6 +35,26 @@ export class CalendarEventRepository {
);
}
public async getByICalUIDs(
iCalUIDs: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<CalendarEventObjectMetadata>[]> {
if (iCalUIDs.length === 0) {
return [];
}
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
return await this.workspaceDataSourceService.executeRawQuery(
`SELECT * FROM ${dataSourceSchema}."calendarEvent" WHERE "iCalUID" = ANY($1)`,
[iCalUIDs],
workspaceId,
transactionManager,
);
}
public async deleteByIds(
calendarEventIds: string[],
workspaceId: string,
@ -80,11 +100,11 @@ export class CalendarEventRepository {
}
public async getICalUIDCalendarEventIdMap(
calendarEventIds: string[],
iCalUIDs: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<Map<string, string>> {
if (calendarEventIds.length === 0) {
if (iCalUIDs.length === 0) {
return new Map();
}
@ -97,8 +117,8 @@ export class CalendarEventRepository {
iCalUID: string;
}[]
| undefined = await this.workspaceDataSourceService.executeRawQuery(
`SELECT id, "iCalUID" FROM ${dataSourceSchema}."calendarEvent" WHERE "id" = ANY($1)`,
[calendarEventIds],
`SELECT id, "iCalUID" FROM ${dataSourceSchema}."calendarEvent" WHERE "iCalUID" = ANY($1)`,
[iCalUIDs],
workspaceId,
transactionManager,
);