Files
CRM_Montzar/apps/api/src/platform/platform.controller.ts
T

208 lines
5.4 KiB
TypeScript
Raw Normal View History

2026-09-19 21:54:21 +03:30
import {
Body,
Controller,
Delete,
2026-09-19 21:54:21 +03:30
Get,
Param,
Patch,
Post,
Put,
2026-09-19 21:54:21 +03:30
Query,
UseGuards,
} from '@nestjs/common';
2026-09-19 22:42:51 +03:30
import { CurrentUser } from '../auth/current-user.decorator';
2026-09-19 21:54:21 +03:30
import {
ApplyBillingPlanDto,
SetStorageQuotaDto,
SetUserCapDto,
2026-09-19 22:42:51 +03:30
CreatePlatformAdminDto,
2026-09-19 21:54:21 +03:30
CreatePlatformOrganizationDto,
2026-09-19 22:42:51 +03:30
ResetPlatformAdminPasswordDto,
SetMasterPasswordDto,
UpdatePlatformAdminDto,
2026-09-19 21:54:21 +03:30
ResetPlatformUserPasswordDto,
UpdateOrgModulesDto,
2026-09-19 21:54:21 +03:30
UpdatePlatformMembershipRoleDto,
UpdatePlatformOrganizationDto,
UpdatePlatformStatusDto,
} from './dto';
import { UpdateConversationSettingsDto } from '../conversations/dto';
2026-09-19 21:54:21 +03:30
import { PlatformAuthGuard } from './platform-auth.guard';
2026-09-19 22:42:51 +03:30
import type { PlatformActor } from './platform-jwt.strategy';
2026-09-19 21:54:21 +03:30
import { PlatformService } from './platform.service';
import { ConversationsService } from '../conversations/conversations.service';
2026-09-19 21:54:21 +03:30
@Controller('platform')
@UseGuards(PlatformAuthGuard)
export class PlatformController {
constructor(
private readonly platform: PlatformService,
private readonly conversations: ConversationsService,
) {}
2026-09-19 21:54:21 +03:30
@Get('stats')
stats() {
return this.platform.stats();
}
@Get('conversations/stats')
conversationStats() {
return this.conversations.platformStats();
}
2026-09-19 22:42:51 +03:30
@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);
}
2026-09-19 21:54:21 +03:30
@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')
2026-09-21 16:38:24 +03:30
listUsers(@Query('q') q?: string, @Query('owners') owners?: string) {
return this.platform.listUsers(q, owners === '1' || owners === 'true');
2026-09-19 21:54:21 +03:30
}
@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);
}
2026-09-19 21:54:21 +03:30
@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);
}
}