ref: format prettier

This commit is contained in:
M1000 2024-12-06 01:15:40 +01:00
parent 38e491dc13
commit 3d131193b6
6 changed files with 43 additions and 35 deletions

View File

@ -2,5 +2,9 @@
"singleQuote": false,
"trailingComma": "all",
"useTabs": true,
"tabWidth": 4
"tabWidth": 4,
"semi": true,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}

View File

@ -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",
};
}
}

View File

@ -1,3 +1,3 @@
export interface JwtPayload {
id: string;
}
export interface JwtPayload {
id: string;
}

View File

@ -1,6 +1,6 @@
export interface Oauth2Profile {
id?: string;
sub?: string;
email: string;
}
export interface Oauth2Profile {
id?: string;
sub?: string;
email: string;
}

View File

@ -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,
},
}),
);

View File

@ -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 ")}`,
);
}