From 3d131193b6e80e3bf2ed9b9c703ab9036bd249e4 Mon Sep 17 00:00:00 2001 From: M1000 Date: Fri, 6 Dec 2024 01:15:40 +0100 Subject: [PATCH] ref: format prettier --- .prettierrc | 6 +++++- src/app.controller.ts | 30 +++++++++++++-------------- src/interfaces/jwtPayload.ts | 6 +++--- src/interfaces/oauth2.ts | 12 +++++------ src/main.ts | 17 +++++++++------ src/modules/auth/guards/role.guard.ts | 7 +++---- 6 files changed, 43 insertions(+), 35 deletions(-) diff --git a/.prettierrc b/.prettierrc index 3a9f34c..3c18acc 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,5 +2,9 @@ "singleQuote": false, "trailingComma": "all", "useTabs": true, - "tabWidth": 4 + "tabWidth": 4, + "semi": true, + "bracketSpacing": true, + "arrowParens": "always", + "endOfLine": "lf" } diff --git a/src/app.controller.ts b/src/app.controller.ts index e748170..a6f02b6 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,15 +1,15 @@ -import { Controller, Get, UseGuards } from "@nestjs/common"; -import { ApiBearerAuth } from "@nestjs/swagger"; -import { JwtAuthGuard } from "./modules/auth/guards/jwt.guard"; - -@Controller() -@ApiBearerAuth() -@UseGuards(JwtAuthGuard) -export class AppController { - @Get("ping") - pong() { - return { - message: "pong", - }; - } -} +import { Controller, Get, UseGuards } from "@nestjs/common"; +import { ApiBearerAuth } from "@nestjs/swagger"; +import { JwtAuthGuard } from "./modules/auth/guards/jwt.guard"; + +@Controller() +@ApiBearerAuth() +@UseGuards(JwtAuthGuard) +export class AppController { + @Get("ping") + pong() { + return { + message: "pong", + }; + } +} diff --git a/src/interfaces/jwtPayload.ts b/src/interfaces/jwtPayload.ts index 8632292..b53d38f 100644 --- a/src/interfaces/jwtPayload.ts +++ b/src/interfaces/jwtPayload.ts @@ -1,3 +1,3 @@ -export interface JwtPayload { - id: string; -} +export interface JwtPayload { + id: string; +} diff --git a/src/interfaces/oauth2.ts b/src/interfaces/oauth2.ts index b95a94a..968f619 100644 --- a/src/interfaces/oauth2.ts +++ b/src/interfaces/oauth2.ts @@ -1,6 +1,6 @@ -export interface Oauth2Profile { - id?: string; - sub?: string; - - email: string; -} +export interface Oauth2Profile { + id?: string; + sub?: string; + + email: string; +} diff --git a/src/main.ts b/src/main.ts index 78c0518..73199f6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,8 @@ -import { ClassSerializerInterceptor, HttpStatus, ValidationPipe } from "@nestjs/common"; +import { + ClassSerializerInterceptor, + HttpStatus, + ValidationPipe, +} from "@nestjs/common"; import { HttpAdapterHost, NestFactory, Reflector } from "@nestjs/core"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; import { PrismaClientExceptionFilter } from "nestjs-prisma"; @@ -16,16 +20,17 @@ async function bootstrap() { new PrismaClientExceptionFilter(httpAdapter, { P2000: { errorMessage: "A required field is missing", - statusCode: HttpStatus.BAD_REQUEST + statusCode: HttpStatus.BAD_REQUEST, }, P2002: { - errorMessage: "A ressource with the same unique fields already exists", - statusCode: HttpStatus.CONFLICT + errorMessage: + "A ressource with the same unique fields already exists", + statusCode: HttpStatus.CONFLICT, }, P2025: { errorMessage: "The requested ressource does not exist", - statusCode: HttpStatus.NOT_FOUND - } + statusCode: HttpStatus.NOT_FOUND, + }, }), ); diff --git a/src/modules/auth/guards/role.guard.ts b/src/modules/auth/guards/role.guard.ts index 4d3d48a..ae4f913 100644 --- a/src/modules/auth/guards/role.guard.ts +++ b/src/modules/auth/guards/role.guard.ts @@ -6,6 +6,7 @@ import { UnauthorizedException, } from "@nestjs/common"; import { Reflector } from "@nestjs/core"; +import { Request } from "express"; @Injectable() export class RolesGuard implements CanActivate { @@ -20,7 +21,7 @@ export class RolesGuard implements CanActivate { return true; } - const request = context.switchToHttp().getRequest(); + const request = context.switchToHttp().getRequest() as Request; const user = request.user; if (!user) { @@ -31,9 +32,7 @@ export class RolesGuard implements CanActivate { if (!hasRole) { throw new UnauthorizedException( - `You need to have the role ${Roles.map((role) => role).join( - " or ", - )}`, + `You need to have the role ${Roles.map((role) => role).join(" or ")}`, ); }