mirror of
https://github.com/docmost/docmost.git
synced 2026-08-21 22:41:36 +10:00
refactor design
This commit is contained in:
@@ -50,6 +50,21 @@ export class IntegrationConnectionService {
|
||||
);
|
||||
}
|
||||
|
||||
async getUserConnections(userId: string, workspaceId: string) {
|
||||
const rows = await this.connectionRepo.findByUserAndWorkspace(
|
||||
userId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
return rows.map((row) => ({
|
||||
integrationId: row.integrationId,
|
||||
type: row.type,
|
||||
isEnabled: row.isEnabled,
|
||||
providerUserId: row.providerUserId ?? null,
|
||||
connectedAt: row.createdAt,
|
||||
}));
|
||||
}
|
||||
|
||||
async disconnect(
|
||||
integrationId: string,
|
||||
userId: string,
|
||||
|
||||
@@ -116,6 +116,16 @@ export class IntegrationController {
|
||||
});
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('connections/mine')
|
||||
async getMyConnections(
|
||||
@AuthUser() user: User,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.connectionService.getUserConnections(user.id, workspace.id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('connection/status')
|
||||
|
||||
@@ -122,6 +122,32 @@ export class IntegrationConnectionRepo {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async findByUserAndWorkspace(
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
trx?: KyselyTransaction,
|
||||
) {
|
||||
const db = dbOrTx(this.db, trx);
|
||||
return db
|
||||
.selectFrom('integrationConnections')
|
||||
.innerJoin(
|
||||
'integrations',
|
||||
'integrations.id',
|
||||
'integrationConnections.integrationId',
|
||||
)
|
||||
.select([
|
||||
'integrationConnections.integrationId',
|
||||
'integrations.type',
|
||||
'integrations.isEnabled',
|
||||
'integrationConnections.providerUserId',
|
||||
'integrationConnections.createdAt',
|
||||
])
|
||||
.where('integrationConnections.userId', '=', userId)
|
||||
.where('integrations.workspaceId', '=', workspaceId)
|
||||
.where('integrations.deletedAt', 'is', null)
|
||||
.execute();
|
||||
}
|
||||
|
||||
async deleteByIntegration(
|
||||
integrationId: string,
|
||||
trx?: KyselyTransaction,
|
||||
|
||||
Reference in New Issue
Block a user