2026-08-29 21:06:30 +03:30
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Param,
|
|
|
|
|
Patch,
|
|
|
|
|
Post,
|
2026-09-15 17:33:05 +03:30
|
|
|
StreamableFile,
|
2026-08-29 21:06:30 +03:30
|
|
|
UseGuards,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import type { UserRole } from '@mento/shared';
|
|
|
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
|
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
|
|
|
import { Roles } from '../auth/roles.decorator';
|
|
|
|
|
import { RolesGuard } from '../auth/roles.guard';
|
2026-09-15 17:33:05 +03:30
|
|
|
import {
|
|
|
|
|
InviteUserDto,
|
|
|
|
|
UpdateUserCommissionDto,
|
|
|
|
|
UpdateUserRoleDto,
|
|
|
|
|
UpdateUserStatusDto,
|
|
|
|
|
} from './dto';
|
2026-08-29 21:06:30 +03:30
|
|
|
import { UsersService } from './users.service';
|
|
|
|
|
|
|
|
|
|
@Controller('users')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
export class UsersController {
|
|
|
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
list(@CurrentUser() user: { organizationId: string }) {
|
|
|
|
|
return this.usersService.list(user.organizationId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-15 17:33:05 +03:30
|
|
|
@Get(':id/avatar')
|
|
|
|
|
async avatar(
|
|
|
|
|
@CurrentUser() user: { organizationId: string },
|
|
|
|
|
@Param('id') id: string,
|
|
|
|
|
) {
|
|
|
|
|
const file = await this.usersService.openAvatar(user.organizationId, id);
|
|
|
|
|
return new StreamableFile(file.stream, { type: file.mimeType });
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 21:06:30 +03:30
|
|
|
@Post()
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
invite(
|
|
|
|
|
@CurrentUser() user: { organizationId: string; role: UserRole },
|
|
|
|
|
@Body() dto: InviteUserDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.usersService.invite(user.organizationId, user.role, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-11 01:09:59 +03:30
|
|
|
@Patch(':id/commission')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
updateCommission(
|
|
|
|
|
@CurrentUser() user: { organizationId: string; role: UserRole },
|
|
|
|
|
@Param('id') id: string,
|
|
|
|
|
@Body() dto: UpdateUserCommissionDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.usersService.updateCommission(
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
id,
|
|
|
|
|
dto.commissionPercent,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-15 17:33:05 +03:30
|
|
|
@Patch(':id/status')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
updateStatus(
|
|
|
|
|
@CurrentUser() user: { organizationId: string; userId: string; role: UserRole },
|
|
|
|
|
@Param('id') id: string,
|
|
|
|
|
@Body() dto: UpdateUserStatusDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.usersService.updateStatus(
|
|
|
|
|
user.organizationId,
|
|
|
|
|
{ userId: user.userId, role: user.role },
|
|
|
|
|
id,
|
|
|
|
|
dto.isActive,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 21:06:30 +03:30
|
|
|
@Patch(':id/role')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
updateRole(
|
|
|
|
|
@CurrentUser() user: { organizationId: string; userId: string; role: UserRole },
|
|
|
|
|
@Param('id') id: string,
|
|
|
|
|
@Body() dto: UpdateUserRoleDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.usersService.updateRole(
|
|
|
|
|
user.organizationId,
|
|
|
|
|
{ userId: user.userId, role: user.role },
|
|
|
|
|
id,
|
2026-09-15 17:33:05 +03:30
|
|
|
dto,
|
2026-08-29 21:06:30 +03:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|