Skip to content

Commit

Permalink
Merge branch 'main' into issue-9458-add-padding-to-iconcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-kraken authored Jan 9, 2025
2 parents 1509f3d + acc3aa6 commit c53b151
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Module } from '@nestjs/common';

import { UserVarsModule } from 'src/engine/core-modules/user/user-vars/user-vars.module';
import { DeleteWorkspaceMemberConnectedAccountsCleanupJob } from 'src/modules/connected-account/jobs/delete-workspace-member-connected-accounts.job';
import { ConnectedAccountWorkspaceMemberListener } from 'src/modules/connected-account/listeners/connected-account-workspace-member.listener';
import { ConnectedAccountListener } from 'src/modules/connected-account/listeners/connected-account.listener';
import { AccountsToReconnectService } from 'src/modules/connected-account/services/accounts-to-reconnect.service';

@Module({
imports: [UserVarsModule],
providers: [AccountsToReconnectService, ConnectedAccountListener],
providers: [
AccountsToReconnectService,
ConnectedAccountListener,
DeleteWorkspaceMemberConnectedAccountsCleanupJob,
ConnectedAccountWorkspaceMemberListener,
],
exports: [AccountsToReconnectService],
})
export class ConnectedAccountModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';

export type DeleteWorkspaceMemberConnectedAccountsCleanupJobData = {
workspaceId: string;
workspaceMemberId: string;
};

@Processor(MessageQueue.deleteCascadeQueue)
export class DeleteWorkspaceMemberConnectedAccountsCleanupJob {
constructor(
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
) {}

@Process(DeleteWorkspaceMemberConnectedAccountsCleanupJob.name)
async handle(
data: DeleteWorkspaceMemberConnectedAccountsCleanupJobData,
): Promise<void> {
const { workspaceId, workspaceMemberId } = data;

const connectedAccountRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ConnectedAccountWorkspaceEntity>(
workspaceId,
'connectedAccount',
);

await connectedAccountRepository.delete({
accountOwnerId: workspaceMemberId,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Injectable } from '@nestjs/common';

import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
import { ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emitter/types/object-record-destroy.event';
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
import {
DeleteWorkspaceMemberConnectedAccountsCleanupJob,
DeleteWorkspaceMemberConnectedAccountsCleanupJobData,
} from 'src/modules/connected-account/jobs/delete-workspace-member-connected-accounts.job';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';

@Injectable()
export class ConnectedAccountWorkspaceMemberListener {
constructor(
@InjectMessageQueue(MessageQueue.deleteCascadeQueue)
private readonly messageQueueService: MessageQueueService,
) {}

@OnDatabaseBatchEvent('workspaceMember', DatabaseEventAction.DESTROYED)
@OnDatabaseBatchEvent('workspaceMember', DatabaseEventAction.DELETED)
async handleWorkspaceMemberRemovalEvent(
payload: WorkspaceEventBatch<
| ObjectRecordDeleteEvent<WorkspaceMemberWorkspaceEntity>
| ObjectRecordDestroyEvent<WorkspaceMemberWorkspaceEntity>
>,
) {
await Promise.all(
payload.events.map((eventPayload) =>
this.messageQueueService.add<DeleteWorkspaceMemberConnectedAccountsCleanupJobData>(
DeleteWorkspaceMemberConnectedAccountsCleanupJob.name,
{
workspaceId: payload.workspaceId,
workspaceMemberId: eventPayload.recordId,
},
),
),
);
}
}

0 comments on commit c53b151

Please sign in to comment.