This commit is contained in:
2026-04-16 17:21:48 +03:00
parent c8fa4c442d
commit c8e7e4e927
116 changed files with 3720 additions and 4197 deletions
+27 -27
View File
@@ -1,27 +1,27 @@
import { Controller, Get, Put, Patch, Body } from '@nestjs/common';
import { Controller, Get, Put, Patch, Body } from "@nestjs/common";
import {
ApiTags,
ApiBearerAuth,
ApiOperation,
ApiOkResponse,
} from '@nestjs/swagger';
import { BaseController } from '../../common/base';
import { UsersService } from './users.service';
} from "@nestjs/swagger";
import { BaseController } from "../../common/base";
import { UsersService } from "./users.service";
import {
CreateUserDto,
UpdateUserDto,
UpdateProfileDto,
ChangePasswordDto,
} from './dto/user.dto';
import { CurrentUser, Roles } from '../../common/decorators';
} from "./dto/user.dto";
import { CurrentUser, Roles } from "../../common/decorators";
import {
ApiResponse,
createSuccessResponse,
} from '../../common/types/api-response.type';
import { User } from '@prisma/client';
} from "../../common/types/api-response.type";
import { User } from "@prisma/client";
import { plainToInstance } from 'class-transformer';
import { UserResponseDto } from './dto/user.dto';
import { plainToInstance } from "class-transformer";
import { UserResponseDto } from "./dto/user.dto";
interface AuthenticatedUser {
id: string;
@@ -29,20 +29,20 @@ interface AuthenticatedUser {
role: string;
}
@ApiTags('Users')
@ApiTags("Users")
@ApiBearerAuth()
@Controller('users')
@Controller("users")
export class UsersController extends BaseController<
User,
CreateUserDto,
UpdateUserDto
> {
constructor(private readonly usersService: UsersService) {
super(usersService, 'User');
super(usersService, "User");
}
@Get('me')
@ApiOperation({ summary: 'Get current authenticated user profile' })
@Get("me")
@ApiOperation({ summary: "Get current authenticated user profile" })
@ApiOkResponse({ type: UserResponseDto })
async getMe(
@CurrentUser() user: AuthenticatedUser,
@@ -50,12 +50,12 @@ export class UsersController extends BaseController<
const fullUser = await this.usersService.findOneWithDetails(user.id);
return createSuccessResponse(
plainToInstance(UserResponseDto, fullUser),
'User profile retrieved successfully',
"User profile retrieved successfully",
);
}
@Put('me')
@ApiOperation({ summary: 'Update current user profile' })
@Put("me")
@ApiOperation({ summary: "Update current user profile" })
@ApiOkResponse({ type: UserResponseDto })
async updateMe(
@CurrentUser() user: AuthenticatedUser,
@@ -64,13 +64,13 @@ export class UsersController extends BaseController<
const updatedUser = await this.usersService.updateProfile(user.id, dto);
return createSuccessResponse(
plainToInstance(UserResponseDto, updatedUser),
'User profile updated successfully',
"User profile updated successfully",
);
}
@Patch('me/password')
@ApiOperation({ summary: 'Change current user password' })
@ApiOkResponse({ description: 'Password changed successfully' })
@Patch("me/password")
@ApiOperation({ summary: "Change current user password" })
@ApiOkResponse({ description: "Password changed successfully" })
async changePassword(
@CurrentUser() user: AuthenticatedUser,
@Body() dto: ChangePasswordDto,
@@ -80,24 +80,24 @@ export class UsersController extends BaseController<
dto.currentPassword,
dto.newPassword,
);
return createSuccessResponse(null, 'Password changed successfully');
return createSuccessResponse(null, "Password changed successfully");
}
// Override create to require admin role
@Roles('admin')
@Roles("admin")
async create(
...args: Parameters<
BaseController<User, CreateUserDto, UpdateUserDto>['create']
BaseController<User, CreateUserDto, UpdateUserDto>["create"]
>
) {
return super.create(...args);
}
// Override delete to require admin role
@Roles('admin')
@Roles("admin")
async delete(
...args: Parameters<
BaseController<User, CreateUserDto, UpdateUserDto>['delete']
BaseController<User, CreateUserDto, UpdateUserDto>["delete"]
>
) {
return super.delete(...args);