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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | 1x 1x 1x 1x 1x 1x 1x 1x 9x 1x 2x 1x 2x 1x 2x 1x 2x | import { Controller, Get, Put, Delete, Body, ValidationPipe, HttpCode, HttpStatus, } from "@nestjs/common"; import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiUnauthorizedResponse, ApiBadRequestResponse, ApiNotFoundResponse, ApiNoContentResponse, } from "@nestjs/swagger"; import { UserService } from "./user.service"; import { CurrentUser } from "../auth/decorators/current-user.decorator"; import { UpdateUserDto } from "./dto/update-user.dto"; import { ChangePasswordDto } from "./dto/change-password.dto"; import { User } from "./user.entity"; import { UserProfile } from "@calendar-todo/shared-types"; @ApiTags("users") @ApiBearerAuth("JWT-auth") @Controller("users") export class UserController { constructor(private readonly userService: UserService) {} @Get("me") @ApiOperation({ summary: "Get current user profile" }) @ApiResponse({ status: 200, description: "Current user profile", schema: { type: "object", properties: { id: { type: "string", example: "user-id-123" }, email: { type: "string", example: "user@example.com" }, username: { type: "string", example: "johndoe", nullable: true }, firstName: { type: "string", example: "John", nullable: true }, lastName: { type: "string", example: "Doe", nullable: true }, profileImage: { type: "string", nullable: true }, emailVerified: { type: "boolean", example: false }, createdAt: { type: "string", format: "date-time" }, }, }, }) @ApiUnauthorizedResponse({ description: "Invalid or missing JWT token", schema: { properties: { statusCode: { type: "number", example: 401 }, message: { type: "string", example: "Unauthorized" }, }, }, }) getProfile(@CurrentUser() user: User): UserProfile { return user.toProfile(); } @Put("me") @ApiOperation({ summary: "Update current user profile" }) @ApiResponse({ status: 200, description: "Updated user profile", schema: { type: "object", properties: { id: { type: "string", example: "user-id-123" }, email: { type: "string", example: "user@example.com" }, username: { type: "string", example: "johndoe", nullable: true }, firstName: { type: "string", example: "John", nullable: true }, lastName: { type: "string", example: "Doe", nullable: true }, profileImage: { type: "string", nullable: true }, emailVerified: { type: "boolean", example: false }, createdAt: { type: "string", format: "date-time" }, }, }, }) @ApiBadRequestResponse({ description: "Invalid input data", schema: { properties: { statusCode: { type: "number", example: 400 }, message: { oneOf: [ { type: "string", example: "Validation failed" }, { type: "array", items: { type: "string" }, example: ["First name cannot be empty"], }, ], }, error: { type: "string", example: "Bad Request" }, }, }, }) @ApiUnauthorizedResponse({ description: "Invalid or missing JWT token", schema: { properties: { statusCode: { type: "number", example: 401 }, message: { type: "string", example: "Unauthorized" }, }, }, }) @ApiNotFoundResponse({ description: "User not found", schema: { properties: { statusCode: { type: "number", example: 404 }, message: { type: "string", example: "User not found" }, error: { type: "string", example: "Not Found" }, }, }, }) async updateProfile( @CurrentUser("id") userId: string, @Body(ValidationPipe) updateUserDto: UpdateUserDto, ): Promise<UserProfile> { return this.userService.update(userId, updateUserDto); } @Put("me/password") @HttpCode(HttpStatus.NO_CONTENT) @ApiOperation({ summary: "Change user password" }) @ApiNoContentResponse({ description: "Password successfully changed", }) @ApiBadRequestResponse({ description: "Invalid input data or current password incorrect", schema: { properties: { statusCode: { type: "number", example: 400 }, message: { oneOf: [ { type: "string", example: "Current password is incorrect" }, { type: "array", items: { type: "string" }, example: ["New password must be at least 8 characters long"], }, ], }, error: { type: "string", example: "Bad Request" }, }, }, }) @ApiUnauthorizedResponse({ description: "Invalid or missing JWT token", schema: { properties: { statusCode: { type: "number", example: 401 }, message: { type: "string", example: "Unauthorized" }, }, }, }) @ApiNotFoundResponse({ description: "User not found", schema: { properties: { statusCode: { type: "number", example: 404 }, message: { type: "string", example: "User not found" }, error: { type: "string", example: "Not Found" }, }, }, }) async changePassword( @CurrentUser("id") userId: string, @Body(ValidationPipe) changePasswordDto: ChangePasswordDto, ): Promise<void> { await this.userService.changePassword(userId, changePasswordDto); } @Delete("me") @HttpCode(HttpStatus.NO_CONTENT) @ApiOperation({ summary: "Delete user account" }) @ApiNoContentResponse({ description: "Account successfully deleted", }) @ApiUnauthorizedResponse({ description: "Invalid or missing JWT token", schema: { properties: { statusCode: { type: "number", example: 401 }, message: { type: "string", example: "Unauthorized" }, }, }, }) @ApiNotFoundResponse({ description: "User not found", schema: { properties: { statusCode: { type: "number", example: 404 }, message: { type: "string", example: "User not found" }, error: { type: "string", example: "Not Found" }, }, }, }) async deleteAccount(@CurrentUser("id") userId: string): Promise<void> { await this.userService.delete(userId); } } |