INSIGHT-MVP/packages/crm-service/src/company-relationships/company-relationships.controller.ts
Thomas Reitz 0ed1e77844 feat(crm): add company detail overhaul with industries, account types, relationship types
- Backend: new CRUD services/controllers for Industries, AccountTypes,
  RelationshipTypes, CompanyRelationships with Prisma schema migration
- Frontend: new hooks, API functions, and types for all config entities
- CompanyDetailPage redesign with ActivityFeed, RelationshipsCard
- CompanyFormModal extended with industry, account type, owner fields
- Activities service now supports companyId filter + includeContacts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 09:21:57 +01:00

82 lines
2.3 KiB
TypeScript

import {
Controller,
Get,
Post,
Delete,
Body,
Param,
ParseUUIDPipe,
HttpCode,
HttpStatus,
UseGuards,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiBearerAuth,
ApiParam,
} from '@nestjs/swagger';
import { CompanyRelationshipsService } from './company-relationships.service';
import { CreateRelationshipDto } from './dto/create-relationship.dto';
import { CurrentUser, JwtPayload } from '../common/decorators';
import { TenantGuard } from '../auth/guards/tenant.guard';
import { singleResponse } from '../common/dto/pagination.dto';
@ApiTags('Company Relationships')
@ApiBearerAuth('access-token')
@UseGuards(TenantGuard)
@Controller('companies/:companyId/relationships')
export class CompanyRelationshipsController {
constructor(
private readonly companyRelationshipsService: CompanyRelationshipsService,
) {}
@Post()
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Unternehmensbeziehung erstellen' })
@ApiParam({ name: 'companyId', type: 'string', format: 'uuid' })
async create(
@CurrentUser() user: JwtPayload,
@Param('companyId', ParseUUIDPipe) companyId: string,
@Body() dto: CreateRelationshipDto,
) {
const rel = await this.companyRelationshipsService.create(
user.tenantId!,
companyId,
user.sub,
dto,
);
return singleResponse(rel);
}
@Get()
@ApiOperation({ summary: 'Beziehungen eines Unternehmens auflisten' })
@ApiParam({ name: 'companyId', type: 'string', format: 'uuid' })
async findAll(
@CurrentUser() user: JwtPayload,
@Param('companyId', ParseUUIDPipe) companyId: string,
) {
const relationships = await this.companyRelationshipsService.findByCompany(
user.tenantId!,
companyId,
);
return { data: relationships };
}
@Delete(':relationshipId')
@ApiOperation({ summary: 'Unternehmensbeziehung loeschen' })
@ApiParam({ name: 'companyId', type: 'string', format: 'uuid' })
@ApiParam({ name: 'relationshipId', type: 'string', format: 'uuid' })
async remove(
@CurrentUser() user: JwtPayload,
@Param('companyId', ParseUUIDPipe) companyId: string,
@Param('relationshipId', ParseUUIDPipe) relationshipId: string,
) {
const rel = await this.companyRelationshipsService.remove(
user.tenantId!,
companyId,
relationshipId,
);
return singleResponse(rel);
}
}