import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query, UseGuards, } from '@nestjs/common'; import { CurrentUser } from '../auth/current-user.decorator'; import { ApplyBillingPlanDto, SetStorageQuotaDto, SetUserCapDto, CreatePlatformAdminDto, CreatePlatformOrganizationDto, ResetPlatformAdminPasswordDto, SetMasterPasswordDto, UpdatePlatformAdminDto, ResetPlatformUserPasswordDto, UpdateOrgModulesDto, UpdatePlatformMembershipRoleDto, UpdatePlatformOrganizationDto, UpdatePlatformStatusDto, } from './dto'; import { UpdateConversationSettingsDto } from '../conversations/dto'; import { PlatformAuthGuard } from './platform-auth.guard'; import type { PlatformActor } from './platform-jwt.strategy'; import { PlatformService } from './platform.service'; import { ConversationsService } from '../conversations/conversations.service'; @Controller('platform') @UseGuards(PlatformAuthGuard) export class PlatformController { constructor( private readonly platform: PlatformService, private readonly conversations: ConversationsService, ) {} @Get('stats') stats() { return this.platform.stats(); } @Get('conversations/stats') conversationStats() { return this.conversations.platformStats(); } @Get('admins') listAdmins() { return this.platform.listAdmins(); } @Post('admins') createAdmin(@Body() dto: CreatePlatformAdminDto) { return this.platform.createAdmin(dto); } @Patch('admins/:id') setAdminActive( @Param('id') id: string, @Body() dto: UpdatePlatformStatusDto, @CurrentUser() actor: PlatformActor, ) { return this.platform.setAdminActive(id, dto.isActive, actor.platformAdminId); } @Patch('admins/:id/password') resetAdminPassword( @Param('id') id: string, @Body() dto: ResetPlatformAdminPasswordDto, ) { return this.platform.resetAdminPassword(id, dto); } @Patch('admins/:id/profile') updateAdmin(@Param('id') id: string, @Body() dto: UpdatePlatformAdminDto) { return this.platform.updateAdmin(id, dto); } @Delete('admins/:id') deleteAdmin(@Param('id') id: string, @CurrentUser() actor: PlatformActor) { return this.platform.deleteAdmin(id, actor.platformAdminId); } @Get('master-password') masterPasswordStatus() { return this.platform.masterPasswordStatus(); } @Put('master-password') setMasterPassword(@Body() dto: SetMasterPasswordDto) { return this.platform.setMasterPassword(dto.password); } @Get('organizations') listOrganizations(@Query('q') q?: string) { return this.platform.listOrganizations(q); } @Post('organizations') createOrganization(@Body() dto: CreatePlatformOrganizationDto) { return this.platform.createOrganization(dto); } @Get('organizations/:id') getOrganization(@Param('id') id: string) { return this.platform.getOrganization(id); } @Patch('organizations/:id') updateOrganization( @Param('id') id: string, @Body() dto: UpdatePlatformOrganizationDto, ) { return this.platform.updateOrganization(id, dto); } @Get('users') listUsers(@Query('q') q?: string, @Query('owners') owners?: string) { return this.platform.listUsers(q, owners === '1' || owners === 'true'); } @Get('users/:id') getUser(@Param('id') id: string) { return this.platform.getUser(id); } @Patch('users/:id') setUserActive(@Param('id') id: string, @Body() dto: UpdatePlatformStatusDto) { return this.platform.setUserActive(id, dto.isActive); } @Patch('users/:id/password') resetUserPassword( @Param('id') id: string, @Body() dto: ResetPlatformUserPasswordDto, ) { return this.platform.resetUserPassword(id, dto); } @Post('users/:id/billing/apply-plan') applyBillingPlan(@Param('id') id: string, @Body() dto: ApplyBillingPlanDto) { return this.platform.applyBillingPlan(id, dto); } @Get('users/:id/storage') storageUsage(@Param('id') id: string, @Query('refresh') refresh?: string) { return this.platform.storageUsage(id, refresh === '1' || refresh === 'true'); } @Patch('users/:id/billing/storage') setStorageQuota(@Param('id') id: string, @Body() dto: SetStorageQuotaDto) { return this.platform.setStorageQuota(id, dto.quotaGb); } @Get('users/:id/seats') seatUsage(@Param('id') id: string) { return this.platform.seatUsage(id); } @Patch('users/:id/billing/users') setUserCap(@Param('id') id: string, @Body() dto: SetUserCapDto) { return this.platform.setUserCap(id, dto.maxUsers); } @Patch('organizations/:id/modules') updateOrganizationModules( @Param('id') id: string, @Body() dto: UpdateOrgModulesDto, ) { return this.platform.updateOrganizationModules(id, dto); } @Get('organizations/:id/conversations/settings') getOrganizationConversationSettings(@Param('id') id: string) { return this.conversations.getSettings(id); } @Patch('organizations/:id/conversations/settings') updateOrganizationConversationSettings( @Param('id') id: string, @Body() dto: UpdateConversationSettingsDto, ) { return this.conversations.upsertSettingsForOrganization(id, dto); } @Patch('memberships/:id') setMembershipActive( @Param('id') id: string, @Body() dto: UpdatePlatformStatusDto, ) { return this.platform.setMembershipActive(id, dto.isActive); } @Patch('memberships/:id/role') updateMembershipRole( @Param('id') id: string, @Body() dto: UpdatePlatformMembershipRoleDto, ) { return this.platform.updateMembershipRole(id, dto.role); } }