ref: format prettier
This commit is contained in:
parent
38e491dc13
commit
3d131193b6
@ -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"
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { Controller, Get, UseGuards } from "@nestjs/common";
|
import { Controller, Get, UseGuards } from "@nestjs/common";
|
||||||
import { ApiBearerAuth } from "@nestjs/swagger";
|
import { ApiBearerAuth } from "@nestjs/swagger";
|
||||||
import { JwtAuthGuard } from "./modules/auth/guards/jwt.guard";
|
import { JwtAuthGuard } from "./modules/auth/guards/jwt.guard";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
export class AppController {
|
export class AppController {
|
||||||
@Get("ping")
|
@Get("ping")
|
||||||
pong() {
|
pong() {
|
||||||
return {
|
return {
|
||||||
message: "pong",
|
message: "pong",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
export interface JwtPayload {
|
export interface JwtPayload {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export interface Oauth2Profile {
|
export interface Oauth2Profile {
|
||||||
id?: string;
|
id?: string;
|
||||||
sub?: string;
|
sub?: string;
|
||||||
|
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
17
src/main.ts
17
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 { 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,
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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 ",
|
|
||||||
)}`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user