feat: drop calendar repository (#5824)

This PR is replacing and removing all the raw queries and repositories
with the new `TwentyORM` and injection system using
`@InjectWorkspaceRepository`.
Some logic that was contained inside repositories has been moved to the
services.
In this PR we're only replacing repositories for calendar feature.

---------

Co-authored-by: Weiko <corentin@twenty.com>
Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2024-06-22 09:26:58 +02:00
committed by GitHub
parent 91b0c2bb8e
commit 0b4bfce324
90 changed files with 979 additions and 1541 deletions

View File

@ -9,6 +9,7 @@ import { MessageChannelRepository } from 'src/modules/messaging/common/repositor
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
import { isDefined } from 'src/utils/is-defined';
export class CanAccessMessageThreadService {
constructor(
@ -46,7 +47,9 @@ export class CanAccessMessageThreadService {
const messageChannelsConnectedAccounts =
await this.connectedAccountRepository.getByIds(
messageChannels.map((channel) => channel.connectedAccountId),
messageChannels
.map((channel) => channel.connectedAccountId)
.filter(isDefined),
workspaceId,
);

View File

@ -211,6 +211,12 @@ export class MessagingErrorHandlingService {
workspaceId,
);
if (!messageChannel.connectedAccountId) {
throw new Error(
`Connected account ID is not defined for message channel ${messageChannel.id} in workspace ${workspaceId}`,
);
}
await this.connectedAccountRepository.updateAuthFailedAt(
messageChannel.connectedAccountId,
workspaceId,

View File

@ -149,7 +149,7 @@ export class MessagingMessageParticipantService {
this.eventEmitter.emit(`messageParticipant.matched`, {
workspaceId,
userId: null,
workspaceMemberId: null,
messageParticipants: updatedMessageParticipants,
});
}

View File

@ -107,7 +107,7 @@ export class MessagingSaveMessagesAndEnqueueContactCreationService {
this.eventEmitter.emit(`messageParticipant.matched`, {
workspaceId,
userId: connectedAccount.accountOwnerId,
workspaceMemberId: connectedAccount.accountOwnerId,
messageParticipants: savedMessageParticipants,
});

View File

@ -35,7 +35,7 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
icon: 'IconHash',
})
@WorkspaceIsNullable()
messageExternalId: string;
messageExternalId: string | null;
@WorkspaceField({
standardId:
@ -46,7 +46,7 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
icon: 'IconHash',
})
@WorkspaceIsNullable()
messageThreadExternalId: string;
messageThreadExternalId: string | null;
@WorkspaceRelation({
standardId:
@ -60,7 +60,7 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
inverseSideFieldKey: 'messageChannelMessageAssociations',
})
@WorkspaceIsNullable()
messageChannel: Relation<MessageChannelWorkspaceEntity>;
messageChannel: Relation<MessageChannelWorkspaceEntity> | null;
@WorkspaceRelation({
standardId: MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.message,
@ -73,7 +73,7 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
inverseSideFieldKey: 'messageChannelMessageAssociations',
})
@WorkspaceIsNullable()
message: Relation<MessageWorkspaceEntity>;
message: Relation<MessageWorkspaceEntity> | null;
@WorkspaceRelation({
standardId:
@ -87,5 +87,5 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
inverseSideFieldKey: 'messageChannelMessageAssociations',
})
@WorkspaceIsNullable()
messageThread: Relation<MessageThreadWorkspaceEntity>;
messageThread: Relation<MessageThreadWorkspaceEntity> | null;
}

View File

@ -162,7 +162,7 @@ export class MessageChannelWorkspaceEntity extends BaseWorkspaceEntity {
icon: 'IconHistory',
})
@WorkspaceIsNullable()
syncedAt: string;
syncedAt: string | null;
@WorkspaceField({
standardId: MESSAGE_CHANNEL_STANDARD_FIELD_IDS.syncStatus,
@ -224,7 +224,7 @@ export class MessageChannelWorkspaceEntity extends BaseWorkspaceEntity {
],
})
@WorkspaceIsNullable()
syncStatus: MessageChannelSyncStatus;
syncStatus: MessageChannelSyncStatus | null;
@WorkspaceField({
standardId: MESSAGE_CHANNEL_STANDARD_FIELD_IDS.syncStage,
@ -282,7 +282,7 @@ export class MessageChannelWorkspaceEntity extends BaseWorkspaceEntity {
icon: 'IconHistory',
})
@WorkspaceIsNullable()
syncStageStartedAt: string;
syncStageStartedAt: string | null;
@WorkspaceField({
standardId: MESSAGE_CHANNEL_STANDARD_FIELD_IDS.throttleFailureCount,

View File

@ -83,7 +83,7 @@ export class MessageParticipantWorkspaceEntity extends BaseWorkspaceEntity {
inverseSideFieldKey: 'messageParticipants',
})
@WorkspaceIsNullable()
person: Relation<PersonWorkspaceEntity>;
person: Relation<PersonWorkspaceEntity> | null;
@WorkspaceRelation({
standardId: MESSAGE_PARTICIPANT_STANDARD_FIELD_IDS.workspaceMember,
@ -96,5 +96,5 @@ export class MessageParticipantWorkspaceEntity extends BaseWorkspaceEntity {
inverseSideFieldKey: 'messageParticipants',
})
@WorkspaceIsNullable()
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity>;
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity> | null;
}

View File

@ -78,7 +78,7 @@ export class MessageWorkspaceEntity extends BaseWorkspaceEntity {
icon: 'IconCalendar',
})
@WorkspaceIsNullable()
receivedAt: string;
receivedAt: string | null;
@WorkspaceRelation({
standardId: MESSAGE_STANDARD_FIELD_IDS.messageThread,
@ -92,7 +92,7 @@ export class MessageWorkspaceEntity extends BaseWorkspaceEntity {
onDelete: RelationOnDeleteAction.CASCADE,
})
@WorkspaceIsNullable()
messageThread: Relation<MessageThreadWorkspaceEntity>;
messageThread: Relation<MessageThreadWorkspaceEntity> | null;
@WorkspaceRelation({
standardId: MESSAGE_STANDARD_FIELD_IDS.messageParticipants,