Download Reactive-Resume/apps/server/src/user/user.controller.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/Reactive-Resume/apps/server/src/user/user.controller.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/Reactive-Resume/apps/server/src/user/user.controller.ts
-
curl -L -o user.controller.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/Reactive-Resume/apps/server/src/user/user.controller.ts
2.33 kB
| import { | |
| BadRequestException, | |
| Body, | |
| Controller, | |
| Delete, | |
| Get, | |
| InternalServerErrorException, | |
| Logger, | |
| Patch, | |
| Res, | |
| UseGuards, | |
| } from "@nestjs/common"; | |
| import { ApiTags } from "@nestjs/swagger"; | |
| import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library"; | |
| import { UpdateUserDto, UserDto } from "@reactive-resume/dto"; | |
| import { ErrorMessage } from "@reactive-resume/utils"; | |
| import type { Response } from "express"; | |
| import { AuthService } from "../auth/auth.service"; | |
| import { TwoFactorGuard } from "../auth/guards/two-factor.guard"; | |
| import { User } from "./decorators/user.decorator"; | |
| import { UserService } from "./user.service"; | |
| ("User") | |
| ("user") | |
| export class UserController { | |
| constructor( | |
| private readonly authService: AuthService, | |
| private readonly userService: UserService, | |
| ) {} | |
| ("me") | |
| (TwoFactorGuard) | |
| fetch(() user: UserDto) { | |
| return user; | |
| } | |
| ("me") | |
| (TwoFactorGuard) | |
| async update(("email") email: string, () updateUserDto: UpdateUserDto) { | |
| try { | |
| // If user is updating their email, send a verification email | |
| if (updateUserDto.email && updateUserDto.email !== email) { | |
| await this.userService.updateByEmail(email, { | |
| emailVerified: false, | |
| email: updateUserDto.email, | |
| }); | |
| await this.authService.sendVerificationEmail(updateUserDto.email); | |
| email = updateUserDto.email; | |
| } | |
| return await this.userService.updateByEmail(email, { | |
| name: updateUserDto.name, | |
| picture: updateUserDto.picture, | |
| username: updateUserDto.username, | |
| locale: updateUserDto.locale, | |
| }); | |
| } catch (error) { | |
| if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") { | |
| throw new BadRequestException(ErrorMessage.UserAlreadyExists); | |
| } | |
| Logger.error(error); | |
| throw new InternalServerErrorException(error); | |
| } | |
| } | |
| ("me") | |
| (TwoFactorGuard) | |
| async delete(("id") id: string, ({ passthrough: true }) response: Response) { | |
| await this.userService.deleteOneById(id); | |
| response.clearCookie("Authentication"); | |
| response.clearCookie("Refresh"); | |
| response.status(200).send({ message: "Sorry to see you go, goodbye!" }); | |
| } | |
| } | |