3369 rename messagerecipients table into messageparticipants (#3457)
* renaming * renaming
This commit is contained in:
@ -8,7 +8,7 @@ import { DataSourceService } from 'src/metadata/data-source/data-source.service'
|
||||
import { DataSourceEntity } from 'src/metadata/data-source/data-source.entity';
|
||||
import {
|
||||
GmailMessage,
|
||||
Recipient,
|
||||
Participant,
|
||||
} from 'src/workspace/messaging/types/gmailMessage';
|
||||
import { GmailThread } from 'src/workspace/messaging/types/gmailThread';
|
||||
import { MessageQuery } from 'src/workspace/messaging/types/messageOrThreadQuery';
|
||||
@ -79,7 +79,7 @@ export class MessagingUtilsService {
|
||||
internalDate,
|
||||
fromHandle,
|
||||
fromDisplayName,
|
||||
recipients,
|
||||
participants,
|
||||
text,
|
||||
} = message;
|
||||
|
||||
@ -127,7 +127,7 @@ export class MessagingUtilsService {
|
||||
);
|
||||
|
||||
await manager.query(
|
||||
`INSERT INTO ${dataSourceMetadata.schema}."messageRecipient" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
|
||||
`INSERT INTO ${dataSourceMetadata.schema}."messageParticipant" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
|
||||
[
|
||||
messageId,
|
||||
'from',
|
||||
@ -138,8 +138,8 @@ export class MessagingUtilsService {
|
||||
],
|
||||
);
|
||||
|
||||
await this.saveMessageRecipients(
|
||||
recipients,
|
||||
await this.saveMessageParticipants(
|
||||
participants,
|
||||
dataSourceMetadata,
|
||||
messageId,
|
||||
manager,
|
||||
@ -148,40 +148,40 @@ export class MessagingUtilsService {
|
||||
}
|
||||
}
|
||||
|
||||
public async saveMessageRecipients(
|
||||
recipients: Recipient[],
|
||||
public async saveMessageParticipants(
|
||||
participants: Participant[],
|
||||
dataSourceMetadata: DataSourceEntity,
|
||||
messageId: string,
|
||||
manager: EntityManager,
|
||||
): Promise<void> {
|
||||
if (!recipients) return;
|
||||
if (!participants) return;
|
||||
|
||||
for (const recipient of recipients) {
|
||||
const recipientPerson = await manager.query(
|
||||
for (const participant of participants) {
|
||||
const participantPerson = await manager.query(
|
||||
`SELECT * FROM ${dataSourceMetadata.schema}."person" WHERE "email" = $1`,
|
||||
[recipient.handle],
|
||||
[participant.handle],
|
||||
);
|
||||
|
||||
const recipientPersonId = recipientPerson[0]?.id;
|
||||
const participantPersonId = participantPerson[0]?.id;
|
||||
|
||||
const workspaceMember = await manager.query(
|
||||
`SELECT "workspaceMember"."id" FROM ${dataSourceMetadata.schema}."workspaceMember"
|
||||
JOIN ${dataSourceMetadata.schema}."connectedAccount" ON ${dataSourceMetadata.schema}."workspaceMember"."id" = ${dataSourceMetadata.schema}."connectedAccount"."accountOwnerId"
|
||||
WHERE ${dataSourceMetadata.schema}."connectedAccount"."handle" = $1`,
|
||||
[recipient.handle],
|
||||
[participant.handle],
|
||||
);
|
||||
|
||||
const recipientWorkspaceMemberId = workspaceMember[0]?.id;
|
||||
const participantWorkspaceMemberId = workspaceMember[0]?.id;
|
||||
|
||||
await manager.query(
|
||||
`INSERT INTO ${dataSourceMetadata.schema}."messageRecipient" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
|
||||
`INSERT INTO ${dataSourceMetadata.schema}."messageParticipant" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
|
||||
[
|
||||
messageId,
|
||||
recipient.role,
|
||||
recipient.handle,
|
||||
recipient.displayName,
|
||||
recipientPersonId,
|
||||
recipientWorkspaceMemberId,
|
||||
participant.role,
|
||||
participant.handle,
|
||||
participant.displayName,
|
||||
participantPersonId,
|
||||
participantWorkspaceMemberId,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user