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, "singleQuote": false,
"trailingComma": "all", "trailingComma": "all",
"useTabs": true, "useTabs": true,
"tabWidth": 4 "tabWidth": 4,
"semi": true,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
} }

View File

@ -1,6 +1,6 @@
export interface Oauth2Profile { export interface Oauth2Profile {
id?: string; id?: string;
sub?: string; sub?: string;
email: 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 { HttpAdapterHost, NestFactory, Reflector } from "@nestjs/core";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { PrismaClientExceptionFilter } from "nestjs-prisma"; import { PrismaClientExceptionFilter } from "nestjs-prisma";
@ -16,16 +20,17 @@ async function bootstrap() {
new PrismaClientExceptionFilter(httpAdapter, { new PrismaClientExceptionFilter(httpAdapter, {
P2000: { P2000: {
errorMessage: "A required field is missing", errorMessage: "A required field is missing",
statusCode: HttpStatus.BAD_REQUEST statusCode: HttpStatus.BAD_REQUEST,
}, },
P2002: { P2002: {
errorMessage: "A ressource with the same unique fields already exists", errorMessage:
statusCode: HttpStatus.CONFLICT "A ressource with the same unique fields already exists",
statusCode: HttpStatus.CONFLICT,
}, },
P2025: { P2025: {
errorMessage: "The requested ressource does not exist", errorMessage: "The requested ressource does not exist",
statusCode: HttpStatus.NOT_FOUND statusCode: HttpStatus.NOT_FOUND,
} },
}), }),
); );

View File

@ -6,6 +6,7 @@ import {
UnauthorizedException, UnauthorizedException,
} from "@nestjs/common"; } from "@nestjs/common";
import { Reflector } from "@nestjs/core"; import { Reflector } from "@nestjs/core";
import { Request } from "express";
@Injectable() @Injectable()
export class RolesGuard implements CanActivate { export class RolesGuard implements CanActivate {
@ -20,7 +21,7 @@ export class RolesGuard implements CanActivate {
return true; return true;
} }
const request = context.switchToHttp().getRequest(); const request = context.switchToHttp().getRequest() as Request;
const user = request.user; const user = request.user;
if (!user) { if (!user) {
@ -31,9 +32,7 @@ export class RolesGuard implements CanActivate {
if (!hasRole) { if (!hasRole) {
throw new UnauthorizedException( throw new UnauthorizedException(
`You need to have the role ${Roles.map((role) => role).join( `You need to have the role ${Roles.map((role) => role).join(" or ")}`,
" or ",
)}`,
); );
} }