Skip to content

Commit

Permalink
added validator
Browse files Browse the repository at this point in the history
  • Loading branch information
uptownhr committed Aug 18, 2023
1 parent 92275dd commit 49f18b3
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 4 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 15 additions & 3 deletions apps/backend/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Get,
Param,
ParseIntPipe,
Post,
UseGuards,
} from '@nestjs/common';

import { AppService } from './app.service';
import { AuthGuard } from '@uptownhr/auth-module';
Expand Down Expand Up @@ -75,7 +83,9 @@ export class AppController {

@ApiResponse({ type: Question, status: 200, isArray: true })
@Get('page/:id/questions')
async getPageQuestions(@Param('id') pageId: number): Promise<Question[]> {
async getPageQuestions(
@Param('id', ParseIntPipe) pageId: number
): Promise<Question[]> {
const questions = await this.lovDb.question.findMany({
where: {
pageId,
Expand Down Expand Up @@ -126,7 +136,9 @@ export class AppController {

@ApiResponse({ type: Answer, status: 200, isArray: true })
@Get('question/:id/answers')
async getQuestionAnswers(@Param('id') questionId: number): Promise<Answer[]> {
async getQuestionAnswers(
@Param('id', ParseIntPipe) questionId: number
): Promise<Answer[]> {
const answers = await this.lovDb.answer.findMany({
where: {
questionId,
Expand Down
9 changes: 8 additions & 1 deletion apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { Logger, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import supertokens from 'supertokens-node';

Expand All @@ -29,6 +29,13 @@ async function bootstrap() {
});

app.useGlobalFilters(new SupertokensExceptionFilter());
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
})
);

const config = new DocumentBuilder()
.setTitle('Questions and Answers')
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"@nestjs/platform-express": "^9.0.0",
"@prisma/client": "^5.1.1",
"axios": "^1.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"posthog-js": "^1.42.2",
"prisma": "^5.1.1",
"reflect-metadata": "^0.1.13",
Expand Down
41 changes: 41 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,13 @@ __metadata:
languageName: node
linkType: hard

"@types/validator@npm:^13.7.10":
version: 13.11.1
resolution: "@types/validator@npm:13.11.1"
checksum: 49e8b611e0b9a0cd645534fd5eeacc64c14ac2f11d7e91d3d8b891f7cf730bccb8a4b7466ac67f4c11e16531bc211a547b97314ca977dd5e58468a77bd0da735
languageName: node
linkType: hard

"@types/ws@npm:^8.5.1":
version: 8.5.4
resolution: "@types/ws@npm:8.5.4"
Expand Down Expand Up @@ -5164,6 +5171,24 @@ __metadata:
languageName: node
linkType: hard

"class-transformer@npm:^0.5.1":
version: 0.5.1
resolution: "class-transformer@npm:0.5.1"
checksum: f191c8b4cc4239990f5efdd790cabdd852c243ed66248e39f6616a349c910c6eed2d9fd1fbf7ee6ea89f69b4f1d0b493b27347fe0cd0ae26b47c3745a805b6d3
languageName: node
linkType: hard

"class-validator@npm:^0.14.0":
version: 0.14.0
resolution: "class-validator@npm:0.14.0"
dependencies:
"@types/validator": ^13.7.10
libphonenumber-js: ^1.10.14
validator: ^13.7.0
checksum: f62e4a0ad24cee68f4b2bc70d32b96de90cb598f96bde362b4dbf4234151af8eb6ae225458312a38fc49fa3959844cf61c60e731a8205e9a570454cff8de2710
languageName: node
linkType: hard

"clean-stack@npm:^2.0.0":
version: 2.2.0
resolution: "clean-stack@npm:2.2.0"
Expand Down Expand Up @@ -9489,6 +9514,13 @@ __metadata:
languageName: node
linkType: hard

"libphonenumber-js@npm:^1.10.14":
version: 1.10.41
resolution: "libphonenumber-js@npm:1.10.41"
checksum: 1f6603e6e561715dc576dc599d347335a454ccb8a7b1355c3aee8957d9748a4a31c0f7a3758c2cfdaed47f3193fa341b5741d37cc55b2fe31181de8352cc476e
languageName: node
linkType: hard

"libphonenumber-js@npm:^1.9.44":
version: 1.10.18
resolution: "libphonenumber-js@npm:1.10.18"
Expand Down Expand Up @@ -14619,6 +14651,8 @@ __metadata:
"@typescript-eslint/parser": ^5.49.0
astro: ^2.0.0
axios: ^1.0.0
class-transformer: ^0.5.1
class-validator: ^0.14.0
cypress: ^12.4.1
eslint: ^8.32.0
eslint-config-prettier: ^8.6.0
Expand Down Expand Up @@ -14733,6 +14767,13 @@ __metadata:
languageName: node
linkType: hard

"validator@npm:^13.7.0":
version: 13.11.0
resolution: "validator@npm:13.11.0"
checksum: d1e0c27022681420756da25bc03eb08d5f0c66fb008f8ff02ebc95812b77c6be6e03d3bd05cf80ca702e23eeb73dadd66b4b3683173ea2a0bc7cc72820bee131
languageName: node
linkType: hard

"vary@npm:^1, vary@npm:~1.1.2":
version: 1.1.2
resolution: "vary@npm:1.1.2"
Expand Down

0 comments on commit 49f18b3

Please sign in to comment.