Calendar event fixes and improvements (#4690)
* fixes * saving workspaceMemberId and personId when saving attendees * add typing * use Map * improve saveMessageParticipants * fix role type * move logic in a service * create new service * use new service in calendar-event-attendee.service * modify service to include more common logic * add defaumt value to isOrganizer in calendar-event-attendee.object-metadata * rename folder * renaming
This commit is contained in:
@ -5,10 +5,7 @@ import { EntityManager } from 'typeorm';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { MessageParticipantObjectMetadata } from 'src/modules/messaging/standard-objects/message-participant.object-metadata';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import {
|
||||
ParticipantWithId,
|
||||
ParticipantWithMessageId,
|
||||
} from 'src/modules/messaging/types/gmail-message';
|
||||
import { ParticipantWithId } from 'src/modules/messaging/types/gmail-message';
|
||||
|
||||
@Injectable()
|
||||
export class MessageParticipantRepository {
|
||||
@ -126,63 +123,4 @@ export class MessageParticipantRepository {
|
||||
|
||||
return messageParticipants;
|
||||
}
|
||||
|
||||
public async saveMessageParticipants(
|
||||
participants: ParticipantWithMessageId[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<void> {
|
||||
if (!participants) return;
|
||||
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
const handles = participants.map((participant) => participant.handle);
|
||||
|
||||
const participantPersonIds =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT id, email FROM ${dataSourceSchema}."person" WHERE "email" = ANY($1)`,
|
||||
[handles],
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
const participantWorkspaceMemberIds =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT "workspaceMember"."id", "connectedAccount"."handle" AS email FROM ${dataSourceSchema}."workspaceMember"
|
||||
JOIN ${dataSourceSchema}."connectedAccount" ON ${dataSourceSchema}."workspaceMember"."id" = ${dataSourceSchema}."connectedAccount"."accountOwnerId"
|
||||
WHERE ${dataSourceSchema}."connectedAccount"."handle" = ANY($1)`,
|
||||
[handles],
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
const messageParticipantsToSave = participants.map((participant) => [
|
||||
participant.messageId,
|
||||
participant.role,
|
||||
participant.handle,
|
||||
participant.displayName,
|
||||
participantPersonIds.find((e) => e.email === participant.handle)?.id,
|
||||
participantWorkspaceMemberIds.find((e) => e.email === participant.handle)
|
||||
?.id,
|
||||
]);
|
||||
|
||||
const valuesString = messageParticipantsToSave
|
||||
.map(
|
||||
(_, index) =>
|
||||
`($${index * 6 + 1}, $${index * 6 + 2}, $${index * 6 + 3}, $${
|
||||
index * 6 + 4
|
||||
}, $${index * 6 + 5}, $${index * 6 + 6})`,
|
||||
)
|
||||
.join(', ');
|
||||
|
||||
if (messageParticipantsToSave.length === 0) return;
|
||||
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`INSERT INTO ${dataSourceSchema}."messageParticipant" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ${valuesString}`,
|
||||
messageParticipantsToSave.flat(),
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user