From 7e1bef8b7eb9fd27cad26f561a9576b8a4084e46 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sat, 23 May 2026 02:02:35 +0100 Subject: [PATCH] feat(integrations): add kind-aware helpers for workspace/user connections --- .../repos/integration-connection.repo.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/apps/server/src/core/integration/repos/integration-connection.repo.ts b/apps/server/src/core/integration/repos/integration-connection.repo.ts index c555affb2..1be4a02c8 100644 --- a/apps/server/src/core/integration/repos/integration-connection.repo.ts +++ b/apps/server/src/core/integration/repos/integration-connection.repo.ts @@ -35,6 +35,7 @@ export class IntegrationConnectionRepo { .selectAll() .where('integrationId', '=', integrationId) .where('userId', '=', userId) + .where('kind', '=', 'workspace') .executeTakeFirst(); } @@ -57,6 +58,7 @@ export class IntegrationConnectionRepo { .where('integrations.type', '=', integrationType) .where('integrations.deletedAt', 'is', null) .where('integrationConnections.userId', '=', userId) + .where('integrationConnections.kind', '=', 'workspace') .executeTakeFirst(); } @@ -158,6 +160,7 @@ export class IntegrationConnectionRepo { .where('refreshToken', 'is not', null) .where('tokenExpiresAt', 'is not', null) .where('tokenExpiresAt', '<', threshold) + .where('kind', '=', 'workspace') .execute(); } @@ -171,4 +174,46 @@ export class IntegrationConnectionRepo { .where('integrationId', '=', integrationId) .execute(); } + + async findWorkspaceConnection( + integrationId: string, + trx?: KyselyTransaction, + ): Promise { + const db = dbOrTx(this.db, trx); + return db + .selectFrom('integrationConnections') + .selectAll() + .where('integrationId', '=', integrationId) + .where('kind', '=', 'workspace') + .executeTakeFirst(); + } + + async findUserLink( + integrationId: string, + providerUserId: string, + trx?: KyselyTransaction, + ): Promise { + const db = dbOrTx(this.db, trx); + return db + .selectFrom('integrationConnections') + .selectAll() + .where('integrationId', '=', integrationId) + .where('providerUserId', '=', providerUserId) + .where('kind', '=', 'user') + .executeTakeFirst(); + } + + async deleteUserLink( + integrationId: string, + userId: string, + trx?: KyselyTransaction, + ): Promise { + const db = dbOrTx(this.db, trx); + await db + .deleteFrom('integrationConnections') + .where('integrationId', '=', integrationId) + .where('userId', '=', userId) + .where('kind', '=', 'user') + .execute(); + } }