mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 09:12:13 +10:00
feat(integrations): add kind-aware helpers for workspace/user connections
This commit is contained in:
@@ -35,6 +35,7 @@ export class IntegrationConnectionRepo {
|
|||||||
.selectAll()
|
.selectAll()
|
||||||
.where('integrationId', '=', integrationId)
|
.where('integrationId', '=', integrationId)
|
||||||
.where('userId', '=', userId)
|
.where('userId', '=', userId)
|
||||||
|
.where('kind', '=', 'workspace')
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ export class IntegrationConnectionRepo {
|
|||||||
.where('integrations.type', '=', integrationType)
|
.where('integrations.type', '=', integrationType)
|
||||||
.where('integrations.deletedAt', 'is', null)
|
.where('integrations.deletedAt', 'is', null)
|
||||||
.where('integrationConnections.userId', '=', userId)
|
.where('integrationConnections.userId', '=', userId)
|
||||||
|
.where('integrationConnections.kind', '=', 'workspace')
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +160,7 @@ export class IntegrationConnectionRepo {
|
|||||||
.where('refreshToken', 'is not', null)
|
.where('refreshToken', 'is not', null)
|
||||||
.where('tokenExpiresAt', 'is not', null)
|
.where('tokenExpiresAt', 'is not', null)
|
||||||
.where('tokenExpiresAt', '<', threshold)
|
.where('tokenExpiresAt', '<', threshold)
|
||||||
|
.where('kind', '=', 'workspace')
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,4 +174,46 @@ export class IntegrationConnectionRepo {
|
|||||||
.where('integrationId', '=', integrationId)
|
.where('integrationId', '=', integrationId)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findWorkspaceConnection(
|
||||||
|
integrationId: string,
|
||||||
|
trx?: KyselyTransaction,
|
||||||
|
): Promise<IntegrationConnection | undefined> {
|
||||||
|
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<IntegrationConnection | undefined> {
|
||||||
|
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<void> {
|
||||||
|
const db = dbOrTx(this.db, trx);
|
||||||
|
await db
|
||||||
|
.deleteFrom('integrationConnections')
|
||||||
|
.where('integrationId', '=', integrationId)
|
||||||
|
.where('userId', '=', userId)
|
||||||
|
.where('kind', '=', 'user')
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user