Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 3x 9x 2x 9x 2x 2x 9x 2x 2x 9x 3x 3x | import {
Body,
Controller,
Delete,
HttpCode,
HttpStatus,
Param,
Post,
Query,
Req,
UseGuards,
Get,
Put,
} from '@nestjs/common';
import { UserService } from './user.service';
import { UserBasicInfoDto, UserDto } from './dto/user.dto';
import { AddSkillDto } from './dto/add-skill.dto';
import { AuthGuard } from '../auth/auth.guard';
import { ApiRequest } from '../auth/types/api-request';
import { UpdateUserDto } from './dto/update-user.dto';
import {
ApiBearerAuth,
ApiBody,
ApiOperation,
ApiParam,
ApiQuery,
ApiTags,
} from '@nestjs/swagger';
@ApiTags('Users')
@ApiBearerAuth()
@Controller('users')
@UseGuards(AuthGuard)
export class UserController {
constructor(private readonly userService: UserService) {}
@Get('search')
@ApiOperation({ summary: 'Search users by name' })
@ApiQuery({
name: 'name',
type: String,
description: 'Name of the user to search for',
})
async searchUsers(@Query('name') name: string): Promise<UserBasicInfoDto[]> {
return this.userService.searchUsers(name);
}
@Get(':id')
@ApiOperation({ summary: 'Get user by ID' })
@ApiParam({ name: 'id', type: String, description: 'ID of the user' })
async getUserById(@Param('id') id: string): Promise<UserDto> {
return await this.userService.getUserById(id);
}
@Put()
@ApiOperation({ summary: 'Update user details' })
@ApiBody({ type: UpdateUserDto, description: 'Updated user information' })
async updateUser(
@Req() req: ApiRequest,
@Body() updateUserDto: UpdateUserDto,
): Promise<{ message: string }> {
const userId = req.user.userId;
return await this.userService.updateUser(userId, updateUserDto);
}
@Delete('skills')
@ApiOperation({ summary: 'Delete a skill from the user' })
@ApiQuery({
name: 'instrumentId',
type: String,
description: 'ID of the skill to delete',
})
@HttpCode(HttpStatus.OK)
async deleteSkill(
@Query('instrumentId') instrumentId: string,
@Req() req: ApiRequest,
): Promise<{ message: string }> {
const userId = req.user.userId;
return await this.userService.deleteSkill(instrumentId, userId);
}
@Post('skills')
@ApiOperation({ summary: 'Add a skill to the user' })
@ApiBody({ type: AddSkillDto, description: 'Skill details to be added' })
@HttpCode(HttpStatus.OK)
async addSkill(
@Req() req: ApiRequest,
@Body() addSkillDto: AddSkillDto,
): Promise<{ message: string }> {
const userId = req.user.userId;
return await this.userService.addSkill(userId, addSkillDto);
}
}
|