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

139 lines
3.4 KiB
TypeScript
Raw Normal View History

2026-09-19 21:54:21 +03:30
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
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,
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,
2026-09-19 21:54:21 +03:30
ResetPlatformUserPasswordDto,
UpdateOrgModulesDto,
2026-09-19 21:54:21 +03:30
UpdatePlatformMembershipRoleDto,
UpdatePlatformOrganizationDto,
UpdatePlatformStatusDto,
} from './dto';
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';
@Controller('platform')
@UseGuards(PlatformAuthGuard)
export class PlatformController {
constructor(private readonly platform: PlatformService) {}
@Get('stats')
stats() {
return this.platform.stats();
}
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);
}
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);
}
@Patch('organizations/:id/modules')
updateOrganizationModules(
@Param('id') id: string,
@Body() dto: UpdateOrgModulesDto,
) {
return this.platform.updateOrganizationModules(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);
}
}