class-validator Questions

4

How to transform database entity User: class User { public firstName: string; public lastName: string; public phone?: string; public email: string; public status: EUserState; public tokens: ...

3

Solved

My "AppState" enum has following possible enum values: export enum AppState { SUCCESS, ERROR, RUNNING } I have a UpdateAppStateDTO with an appState which should accept every enum val...
Castlereagh asked 3/3, 2020 at 10:55

1

Solved

I want to make fields required based on another field in the DTO itself. Currently my DTO looks like: import { LOGIN_TYPE } from "src/utils/constants"; import { IsIn, IsNotEmpty, IsOption...
Erotomania asked 29/7, 2023 at 13:13

5

Solved

I want to apply validation on request payload like, there is field name with string type. But name is not compulsory field but if it exist it must execute @IsNotEmpty() I tried something like this...
Tulley asked 8/4, 2019 at 10:53

3

Solved

I have anum like this: export enum UserRole { USER, ADMIN, BLOGGER } and create.user.dto like this import { IsEmail, IsEnum, IsNotEmpty, IsOptional } from 'class-validator'; import { UserRole }...
Kentish asked 19/4, 2020 at 20:54

6

Solved

I am using class-validator package with NestJS and I am looking to validate an array of objects that need to have exactly 2 objects with the same layout: So far I have: import { IsString, IsNumbe...
Elviaelvie asked 11/10, 2019 at 14:21

4

I have TypeScript NestJS project. I need to validate incoming DTO to my API. It can be described as "creating of project" where we have type of building (House, Flat, Garden) and depending on that...
Alcaic asked 14/2, 2020 at 10:3

3

Solved

I'm using the built in NestJS ValidationPipe along with class-validator and class-transformer to validate and sanitize inbound JSON body payloads. One scenario I'm facing is a mixture of upper and ...
Swamy asked 29/12, 2020 at 3:24

1

I'm trying to write a custom validator. The thing is that my validation depends on an attribute of the user that is making the request. I'm using passport so the user is attached to the context and...
Hematuria asked 7/3, 2023 at 18:45

5

I want to validate the Address field, it may contain numbers or strings, but it should not accept continuous empty spaces @IsAlphaNumeric() Address: string; I want the Address to be numeric or alp...
Infringement asked 25/3, 2019 at 7:50

3

I have a rest call, which might receive body of type classA or classB. I need to keep it as 2 different classes. Example - // classes - class ClassA { @IsString() @Length(1, 128) public readonly...
Elsyelton asked 15/7, 2021 at 16:22

4

Solved

I want to apply server-side validation on my CRUD API. The entity in question is called Employee. I am using an employee.dto (shown below) for the create and update endpoints. The class-validator p...

2

Solved

I have a DTO in which I have a field which is an array of numbers. These ids are coming via API query parameters. I am using Class Transformer to transform these ids into an array of numbers. But I...
Hamamatsu asked 23/10, 2020 at 6:12

3

I'm trying to perform simple validation on a JSON input, modelled by one of my DTOs. One of the object properties is of type Map<string, number>. an example input: { "type": "...
Gongorism asked 29/7, 2021 at 13:22

5

Creating a new user will ignore non-specified objects from create-user.dto.ts However when I update the user it will add unwanted fields like this: // update-user.dto.ts import { IsEmail } from '...
Sula asked 21/2, 2019 at 17:44

1

If I want to validate the role which user post to api to create if is unique of relation enterprise @Injectable({ scope: Scope.REQUEST }) @ValidatorConstraint({ name: 'Ddd', async: true }) export c...
Assyria asked 13/10, 2020 at 10:44

0

Request Body: [ { fname: "fname", lname: "lname", }, { fname: "fname1", lname: "lname1", grades: { quiz1: 75, quiz3: 85, }, ... ] Model: export ...
Jay asked 8/9, 2022 at 19:41

3

Solved

At the moment, I have a very simple class-validator file with a ValidationPipe in Nest.js as follows: import { IsDateString, IsEmail, IsOptional, IsString, Length, Max, } from 'class-validato...
Alsatian asked 29/1, 2022 at 17:23

2

Solved

When I went through Pipes documentation I noticed that I can't make @IsInt() validation for application/x-www-form-urlencoded request correctly, cause all values which I passed I receive as string ...
Repellent asked 25/2, 2018 at 20:55

1

Let's say one has a class, Post, that one wants to validate. export class Post { @IsArray() tags: string[]; } Let's now say that he wants to ensure that the word 'mistake' never appears in the t...
Catholicism asked 4/8, 2020 at 19:40

1

Solved

I have an simple DTO class for validation class SearchIssuerDto { search: string | number; } What is the correct way to validate the search param that it can accept an string or a number ?
Gayl asked 17/5, 2022 at 10:21

3

Solved

I have a signup DTO where one member is dependent of another. The IsPostalCode on zip needs to know the countryCode/locale, which is one of the other class members. Is it possible to use a class me...
Vampirism asked 16/2, 2021 at 12:36

1

Solved

so I was building an API where by user gives us type and value in the request body, type could be CNIC, EMAIL, MOBILE Now based on the type I have to validate the value like if EMAIL is valid or if...
Melda asked 22/3, 2022 at 9:20

1

Solved

Most of my NestJs controllers look the same. They have basic CRUD functionality and do the exact same things. The only differences between the controllers are: the path the service that is injecte...
Spontaneous asked 8/3, 2022 at 12:8

1

I am using class-validator for validate data, I need to implement validation for file upload. Ex: file is not empty (It would be great if also implement file must be image). I try in following way:...
Canescent asked 14/3, 2020 at 7:24

© 2022 - 2024 — McMap. All rights reserved.