3ab647be2e
Backend: - Added TECHNICAL and SALES roles to UserRole enum - Added TicketDepartment, TicketStatus, TicketPriority enums - Created Ticket and TicketMessage entities with relationships - Created TicketsModule with full CRUD service and controller - Ticket routing: users create tickets to technical/sales departments - Staff reply updates status (answered), user reply sets waiting - Role-based access: technical staff sees technical tickets, sales sees sales tickets - Admin sees all tickets with stats (total, open, avg response time) - Updated access control: technical role has admin-level access (except role change) - Sales role can view users and handle sales tickets - Clusters controller: technical role can manage clusters/pools - Users controller: technical/sales can view users, only admin changes roles Frontend: - New user ticket pages: list (with create form) + detail (chat-style messages) - Staff ticket panel: filtered by department with status filters - Admin all-tickets page with statistics dashboard and department/status filters - Updated sidebar: role-based nav items (admin/technical/sales sections) - Role badges in header for technical (blue) and sales (green) - Admin users page: new roles in dropdowns, role change restricted to admin only - Deploy page: technical role gets cluster selection access like admin
131 lines
4.5 KiB
TypeScript
131 lines
4.5 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { ClustersService } from './clusters.service';
|
|
import { CreateClusterDto, UpdateClusterDto } from './dto/cluster.dto';
|
|
import { CreateClusterPoolDto, UpdateClusterPoolDto } from './dto/cluster-pool.dto';
|
|
import { RolesGuard } from '../common/guards/roles.guard';
|
|
import { Roles } from '../common/decorators/roles.decorator';
|
|
import { UserRole } from '../common/enums';
|
|
|
|
@ApiTags('Clusters')
|
|
@ApiBearerAuth()
|
|
@Controller('clusters')
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
export class ClustersController {
|
|
constructor(private readonly clustersService: ClustersService) {}
|
|
|
|
// ─── Public endpoints (any authenticated user) ────────────────────
|
|
|
|
@Get('public')
|
|
@ApiOperation({ summary: 'List available clusters (public info, no kubeconfig)' })
|
|
async findAllPublic() {
|
|
return this.clustersService.findAllPublic();
|
|
}
|
|
|
|
@Get('pools/public')
|
|
@ApiOperation({ summary: 'List active cluster pools with resolved cluster names' })
|
|
async findAllPoolsPublic() {
|
|
return this.clustersService.findAllPoolsPublic();
|
|
}
|
|
|
|
// ─── Cluster admin endpoints ──────────────────────────────────────
|
|
|
|
@Post()
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Register a new Kubernetes cluster (Admin/Technical)' })
|
|
async create(@Body() dto: CreateClusterDto) {
|
|
return this.clustersService.create(dto);
|
|
}
|
|
|
|
@Get()
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'List all clusters (Admin/Technical)' })
|
|
async findAll() {
|
|
return this.clustersService.findAll();
|
|
}
|
|
|
|
@Get(':id/resources')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Get cluster resource usage — nodes, CPU, memory, pods (Admin/Technical)' })
|
|
async getClusterResources(@Param('id') id: string) {
|
|
return this.clustersService.getClusterResources(id);
|
|
}
|
|
|
|
@Get(':id')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Get cluster details (Admin/Technical)' })
|
|
async findOne(@Param('id') id: string) {
|
|
return this.clustersService.findOne(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Update cluster configuration (Admin/Technical)' })
|
|
async update(@Param('id') id: string, @Body() dto: UpdateClusterDto) {
|
|
return this.clustersService.update(id, dto);
|
|
}
|
|
|
|
@Post(':id/test')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Test connectivity to a registered cluster (Admin/Technical)' })
|
|
async testConnection(@Param('id') id: string) {
|
|
return this.clustersService.testClusterById(id);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Remove a cluster (Admin/Technical)' })
|
|
async delete(@Param('id') id: string) {
|
|
await this.clustersService.delete(id);
|
|
return { message: 'Cluster deleted' };
|
|
}
|
|
|
|
// ─── Cluster Pool admin endpoints ─────────────────────────────────
|
|
|
|
@Post('pools')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Create a cluster pool for load balancing (Admin/Technical)' })
|
|
async createPool(@Body() dto: CreateClusterPoolDto) {
|
|
return this.clustersService.createPool(dto);
|
|
}
|
|
|
|
@Get('pools')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'List all cluster pools (Admin/Technical)' })
|
|
async findAllPools() {
|
|
return this.clustersService.findAllPools();
|
|
}
|
|
|
|
@Get('pools/:id')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Get cluster pool details (Admin/Technical)' })
|
|
async findOnePool(@Param('id') id: string) {
|
|
return this.clustersService.findOnePool(id);
|
|
}
|
|
|
|
@Patch('pools/:id')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Update cluster pool (Admin/Technical)' })
|
|
async updatePool(@Param('id') id: string, @Body() dto: UpdateClusterPoolDto) {
|
|
return this.clustersService.updatePool(id, dto);
|
|
}
|
|
|
|
@Delete('pools/:id')
|
|
@Roles(UserRole.ADMIN, UserRole.TECHNICAL)
|
|
@ApiOperation({ summary: 'Delete a cluster pool (Admin/Technical)' })
|
|
async deletePool(@Param('id') id: string) {
|
|
await this.clustersService.deletePool(id);
|
|
return { message: 'Cluster pool deleted' };
|
|
}
|
|
}
|