All files / src/platform/integrations/controllers integrations.controller.ts

0% Statements 0/31
0% Branches 0/4
0% Functions 0/9
0% Lines 0/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82                                                                                                                                                                   
import { Controller, Get, Post, Put, Param, Body, Req } from '@nestjs/common';
import { IntegrationRegistryService } from '../services/integration-registry.service';
import {
  ApiTags,
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
} from '@nestjs/swagger';
 
@ApiTags('Integrations')
@ApiBearerAuth()
@Controller('api/v1/integrations')
export class IntegrationsController {
  constructor(private readonly registry: IntegrationRegistryService) {}
 
  @Get()
  @ApiOperation({ summary: 'List all active integrations for the tenant' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async list(@Req() req: any) {
    const tenantId = req.user?.tenantId;
    return this.registry.getActiveTenantIntegrations(tenantId);
  }
 
  @Get('available')
  @ApiOperation({ summary: 'List all available system integration keys' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async listAvailable() {
    return this.registry.listProviders();
  }
 
  @Get(':key')
  @ApiOperation({ summary: 'Get integration details for a specific key' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async get(@Req() req: any, @Param('key') key: string) {
    const tenantId = req.user?.tenantId;
    return this.registry.getTenantIntegration(tenantId, key);
  }
 
  @Post(':key/connect')
  @ApiOperation({ summary: 'Connect an integration for the tenant' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  async connect(@Req() req: any, @Param('key') key: string, @Body() body: any) {
    const tenantId = req.user?.tenantId;
    const userId = req.user?.userId;
    return this.registry.connect(tenantId, key, body.settings, userId);
  }
 
  @Post(':key/test')
  @ApiOperation({ summary: 'Test the connection for an integration' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  async test(@Req() req: any, @Param('key') key: string) {
    const tenantId = req.user?.tenantId;
    return this.registry.testConnection(tenantId, key);
  }
 
  @Post(':key/disconnect')
  @ApiOperation({ summary: 'Disconnect an integration for the tenant' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  async disconnect(@Req() req: any, @Param('key') key: string) {
    const tenantId = req.user?.tenantId;
    return this.registry.disconnect(tenantId, key);
  }
 
  @Get(':key/logs')
  @ApiOperation({ summary: 'Get integration activity logs' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getLogs(@Req() req: any, @Param('key') key: string) {
    const tenantId = req.user?.tenantId;
    return this.registry.getHealthLogs(tenantId, key);
  }
 
  @Get(':key/health')
  @ApiOperation({
    summary: 'Get latest health check result for an integration',
  })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getHealth(@Req() req: any, @Param('key') key: string) {
    const tenantId = req.user?.tenantId;
    return this.registry.testConnection(tenantId, key);
  }
}