INSIGHT-MVP/packages/crm-service/src/pipelines/pipelines.controller.ts
Thomas Reitz c9e2c4a44c feat(crm): add PATCH endpoint for pipeline stages + HTTPS router
- New PATCH /pipelines/:id/stages/:stageId endpoint to update
  stage name, color, and sortOrder
- Added HTTPS (websecure) Traefik router for CRM service
- Both requested by frontend developer via INSIGHT-CRM.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:22:33 +01:00

155 lines
4.3 KiB
TypeScript

import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
ParseUUIDPipe,
HttpCode,
HttpStatus,
UseGuards,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiBearerAuth,
ApiParam,
} from '@nestjs/swagger';
import { PipelinesService } from './pipelines.service';
import { CreatePipelineDto, CreatePipelineStageDto } from './dto/create-pipeline.dto';
import { UpdatePipelineDto } from './dto/update-pipeline.dto';
import { UpdateStageDto } from './dto/update-stage.dto';
import { CurrentUser, JwtPayload } from '../common/decorators';
import { TenantGuard } from '../auth/guards/tenant.guard';
import { singleResponse } from '../common/dto/pagination.dto';
@ApiTags('Pipelines')
@ApiBearerAuth('access-token')
@UseGuards(TenantGuard)
@Controller('pipelines')
export class PipelinesController {
constructor(private readonly pipelinesService: PipelinesService) {}
@Post()
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Pipeline erstellen' })
async create(
@CurrentUser() user: JwtPayload,
@Body() dto: CreatePipelineDto,
) {
const pipeline = await this.pipelinesService.create(
user.tenantId!,
user.sub,
dto,
);
return singleResponse(pipeline);
}
@Get()
@ApiOperation({ summary: 'Alle Pipelines auflisten' })
async findAll(@CurrentUser() user: JwtPayload) {
const pipelines = await this.pipelinesService.findAll(user.tenantId!);
return {
success: true,
data: pipelines,
meta: { timestamp: new Date().toISOString() },
};
}
@Get(':id')
@ApiOperation({ summary: 'Pipeline-Details abrufen' })
@ApiParam({ name: 'id', type: 'string', format: 'uuid' })
async findOne(
@CurrentUser() user: JwtPayload,
@Param('id', ParseUUIDPipe) id: string,
) {
const pipeline = await this.pipelinesService.findOne(user.tenantId!, id);
return singleResponse(pipeline);
}
@Patch(':id')
@ApiOperation({ summary: 'Pipeline aktualisieren' })
@ApiParam({ name: 'id', type: 'string', format: 'uuid' })
async update(
@CurrentUser() user: JwtPayload,
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: UpdatePipelineDto,
) {
const pipeline = await this.pipelinesService.update(
user.tenantId!,
id,
user.sub,
dto,
);
return singleResponse(pipeline);
}
@Delete(':id')
@ApiOperation({ summary: 'Pipeline loeschen' })
@ApiParam({ name: 'id', type: 'string', format: 'uuid' })
async remove(
@CurrentUser() user: JwtPayload,
@Param('id', ParseUUIDPipe) id: string,
) {
const pipeline = await this.pipelinesService.remove(user.tenantId!, id);
return singleResponse(pipeline);
}
// Stage Management
@Post(':id/stages')
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Stufe zur Pipeline hinzufuegen' })
@ApiParam({ name: 'id', type: 'string', format: 'uuid' })
async addStage(
@CurrentUser() user: JwtPayload,
@Param('id', ParseUUIDPipe) pipelineId: string,
@Body() dto: CreatePipelineStageDto,
) {
const stage = await this.pipelinesService.addStage(
user.tenantId!,
pipelineId,
dto.name,
dto.sortOrder ?? 0,
dto.color,
);
return singleResponse(stage);
}
@Patch(':id/stages/:stageId')
@ApiOperation({ summary: 'Stufe aktualisieren (Name, Farbe, Reihenfolge)' })
@ApiParam({ name: 'id', type: 'string', format: 'uuid' })
@ApiParam({ name: 'stageId', type: 'string', format: 'uuid' })
async updateStage(
@CurrentUser() user: JwtPayload,
@Param('id', ParseUUIDPipe) pipelineId: string,
@Param('stageId', ParseUUIDPipe) stageId: string,
@Body() dto: UpdateStageDto,
) {
const stage = await this.pipelinesService.updateStage(
user.tenantId!,
pipelineId,
stageId,
dto,
);
return singleResponse(stage);
}
@Delete(':id/stages/:stageId')
@ApiOperation({ summary: 'Stufe aus Pipeline entfernen' })
@ApiParam({ name: 'id', type: 'string', format: 'uuid' })
@ApiParam({ name: 'stageId', type: 'string', format: 'uuid' })
async removeStage(
@CurrentUser() user: JwtPayload,
@Param('id', ParseUUIDPipe) pipelineId: string,
@Param('stageId', ParseUUIDPipe) stageId: string,
) {
const stage = await this.pipelinesService.removeStage(
user.tenantId!,
pipelineId,
stageId,
);
return singleResponse(stage);
}
}