class-validator Questions

5

I want to create a NestJs API with TypeORM and MongoDB. My entity id fields are of type ObjectID. The controller routes should validate the incoming ids before passing them to the services. I know ...
Dentiform asked 19/2, 2020 at 14:46

3

Solved

I'm writing a registration endpoint for an api i'm working on and i'm using nestjs and class-validator to validate the input data. The user can register using either their phone number or email add...
Feminacy asked 30/6, 2019 at 17:22

3

How to do validation with database like unique filed validation in nest JS using the class validator? I created a custom validation class and tried it. But userService was undefined when I console ...
Stratify asked 7/3, 2023 at 9:51

7

Solved

I'm setting up a new NestJS application, and I've just added class-validator in order to validate controller input, but it seems to be completely ignored. This is the DTO: import {IsString} from '...
Willful asked 10/3, 2020 at 11:41

4

Solved

I'm trying to inject my users service into my validator constraint interface but it doesn't seem to work: import { ValidatorConstraintInterface, ValidatorConstraint, ValidationArguments, registerD...
Peart asked 4/2, 2020 at 17:8

3

I am trying to validate an array of objects using DTO in nestjs. I have tried it but the data is not getting validated. I tried to search a lot but didn't get any answer. These are my files: trivia...
Bread asked 21/5, 2021 at 5:40

2

Solved

I am working on a nest project, and using class-validator for validation. Currently if there is any validation error, I am getting error response as { "statusCode": 400, "message&q...
Wagonage asked 27/2, 2023 at 14:22

3

Solved

I'm trying to find a nice way to validate a body using DTO (using the brilliant class-validator and class-transformer libraries). It works really well, even for nested structures but in my case I'd...
Monseigneur asked 5/1, 2019 at 22:47

11

Solved

Today, I am trying to figure out how to validate a Sign Up form in the backend side (NestJS) of the app. I am just wondering if exists a way to validate password and passwordConfirm matching, using...
Ergograph asked 28/2, 2020 at 12:2

1

I have a NestJs dto that looks like this import { IsEmail, IsNotEmpty, IsNotIn } from 'class-validator'; import { AppService } from './app.service'; const restrictedNames = ['Name Inc', 'Acme Inc']...
Conker asked 22/5, 2023 at 5:47

4

Solved

I am trying to use a ValidationPipe but no matter how I write my code I get the following warning when sending a request: No metadata found. There is more than once class-validator version installe...
Dougald asked 3/4, 2019 at 9:1

3

Solved

Is there a way to set the execution order of decorators when describing a DTO class in NestJS using class-validator and class-transformer packages ? Following code fails when the value of foo is se...

6

Solved

import { isEmail, isEmpty, isPhoneNumber, Length } from "class-validator" import { Field, InputType } from "type-graphql"; @InputType() export class RegisterInput { @Field() ...
Liebman asked 11/4, 2021 at 13:9

2

Solved

I'm trying to validate the number of digits for numeric values using class-validator. For example: my entity can accept only numbers of 6 digits for a given property. This way const user1 = new Use...
Ejaculatory asked 17/2, 2022 at 14:20

7

Solved

I'm new to NestJS and I am trying to fill a filter DTO from query Parameters. Here is what I have: Query: localhost:3000/api/checklists?stations=114630,114666,114667,114668 Controller @Get() p...
Stere asked 11/12, 2019 at 16:1

2

Solved

I'm trying to validate the parameters that come in the query of a get request, but for some reason, the validation pipe is unable to identify the elements of the query. import { Controller, Post...
Szymanski asked 29/3, 2019 at 18:47

2

That's the error thrown by class-validator. Here is the code for my dto: export class UpdateEntryBodyDto { @ApiProperty() @Type(() => Number) @IsNumber() id: number; @ApiProperty() @IsStr...
Eratosthenes asked 6/7, 2020 at 15:51

2

Solved

Is it possible to return a custom error response from class-validator inside of NestJs. NestJS currently returns an error message like this: { "statusCode": 400, "error": "Bad Request", "messa...
Soracco asked 6/9, 2019 at 10:44

1

I have a NestJS project in which I'm using both class validator and class transformer, and I need the class-transformer to execute before the class-validator throws an error. Given the following c...
Eatables asked 12/12, 2019 at 17:22

3

Solved

Using class-validator along with NestJS I want to validate that a user provides either propertyA or a propertyB but they don't need to provide both. Currently, I'm doing something like: export clas...
Elaelaborate asked 5/2, 2022 at 0:38

2

Is it possible to inject execution context or access current request in nestJs (class-validator => custom validator) ? import { ValidatorConstraint, ValidatorConstraintInterface, ValidationArgumen...
Octahedrite asked 13/9, 2018 at 16:4

9

Consider this endpoint in my API: @Post('/convert') @UseInterceptors(FileInterceptor('image')) convert( @UploadedFile() image: any, @Body( new ValidationPipe({ validationError: { target: fa...
Erdrich asked 26/11, 2019 at 8:28

2

Solved

In the nest.js application on controller level I have to validate DTO. I've faced with difficulty to check if item is not null (request should be rejected if any list item is null or undefined) Cod...
Ytterbium asked 4/10, 2021 at 15:5

5

Let's have this controller in NestJS project: @Post('resetpassword') @HttpCode(200) async requestPasswordReset( @Body() body: RequestPasswordResetDTO, ): Promise<boolean> { try { retu...
Roan asked 17/2, 2020 at 21:13

2

Solved

How to check whether the array is empty or not using class-validator. Given below is my structure. I want to check if cartId is empty or not. { "cartId": [] }
Grenadine asked 17/4, 2020 at 6:5

© 2022 - 2024 — McMap. All rights reserved.