435 questions
0
votes
0
answers
50
views
nestjs use i18n in decorators of class-validator without indicate one by one
I'm researching that can I use i18n for the messages of validation exceptions. For example:
create-user.dto.ts
export default class createUserDto {
@MinLength(5)
@IsString()
name: string;
}...
0
votes
1
answer
58
views
How to validate nested array of object by groups in Nestjs with class-validator
Consider following Dtos:
export class Child {
@ApiProperty({
type: String,
isArray: true,
})
name: string;
@ApiProperty({
type: Number,
isArray: true,
})
age: number;
}
...
0
votes
0
answers
33
views
How to assign validation result to a field using class-validator in NestJS?
I am working on a NestJS project where I use class-validator to validate incoming DTOs. I have a custom validator @IsAccessPointExists() that checks if an access point exists in the database. The ...
1
vote
1
answer
68
views
class-validator whitelisting properties of object inside array
I´m trying to validate the body of a route on NestJS and i´m using the class-validator package, my route is receiving the data as multipat because this route also accepts a file upload. Here is the ...
1
vote
0
answers
94
views
Issue with IsEnum Decorator on an Optional Property in Nestjs
I am working with NestJS and trying to apply the IsEnum decorator to an optional property. However, I am encountering an error.
I am using "class-validator": "^0.14.1" and my DTO ...
1
vote
1
answer
128
views
Unable to POST data using Nuxt's useFetch()
I try to send login credentials to my NestJS API. API uses class-validator to validate incoming requests' bodies.
// auth.controller.ts
@Post('login')
async login(@Res({ passthrough: true }) response: ...
1
vote
0
answers
84
views
Express middleware for DTO validation throws undefined TypeError on valid payload
I have a POST /login route in my Express application where I'm using a payload validation middleware before the controller, structured as follows:
profileRouter.post(
"/login",
...
2
votes
1
answer
325
views
NestJs Class validation for generic class
I am building a NestJS application with a pagination API that includes filtering and searching capabilities. To handle this, I created an abstract class, PaginationAbstract, which accepts two generic ...
0
votes
1
answer
80
views
ValidationPipe doesn't transform string to number
I use: @UsePipes(new ValidationPipe({ transform: true })) to transform query param criteria to specific types, but it doesn't work for numbers, can you explain me why?
Version of @bx/nestjs-commons - ...
-1
votes
1
answer
258
views
NestJS: DTO transform default values not working if parameter is not passed in the payload
I've created a controller that receives a POST/ ... request.
one of the parameters is optional and it's for example called contentType.
in the service i check if the contentType is equal to something ...
0
votes
2
answers
73
views
ValidateIf() is not working as expected . Not Validating (NestJS)
I am using validateIf() to check if the paymentService is equal to some enum value defined in my code. But it does not validate and throws an error .
@ApiProperty({ required: true })
@...
0
votes
1
answer
115
views
How to set DTO props as optional, but never allow all of them null?
I'm trying to apply a validation using class-validator to make possible that some props can be @IsOptional, but if all of them is null, throw an exception.
Thinking in some approach like this:
@...
0
votes
1
answer
63
views
NestJS validate null payload
I'm writing input validation for an event handler. The payload can be either an Order object or null. I need some help on how to allow null payloads in this setup, as they are currently rejected.
Here ...
1
vote
1
answer
217
views
Custom class validator in nest js, usage for complex validation
We generally work as, doing validation and doing all sort of validation in validator and we expect that if the request reaches controller it has already been validated againsts all the application ...
2
votes
0
answers
683
views
Payload validation with tsoa and class-validator in express js
I am using tsoa with class-validator in express js
Now when i define DTO with class-validator and define type for body in tsoa route, it only validates the datataype of the body object values & if ...
0
votes
0
answers
64
views
Is optional if other properties are undefined
I have the following DTO
export class UpsertSubscription {
@Expose()
@ValidateIf((o) => !o.monthly && !o.yearly)
@IsNumber({}, { message: 'tiers.priceMustBeANumber' })
@Min(0, { ...
2
votes
0
answers
564
views
NestJS: Handling Empty Objects in Array Validation with Class-Validator
I'm working with NestJS and using class-validator to validate data. I have an array of objects in my DTO, but I need to ensure that empty objects (objects with no properties) are eliminated from the ...
1
vote
1
answer
136
views
Custom validator via class-validator has null pointer
I have this:
import * as val from 'class-validator';
import {ObjectId as MongoId} from 'mongodb';
@val.ValidatorConstraint({async: false})
export class IsTraceValidConstraint ...
0
votes
3
answers
6k
views
Nestjs + Class-validator: Validating decimal values
I just ran into a pretty simple issue, this definition normally should have worked perfectly and pass the validation as price field in JSON is already sent in decimal format as you can figure below, ...
0
votes
0
answers
92
views
How to use MongoDB query operators in TypeScript DTO with class-validator?
Here is what I want to achieve. My current QueryUserDto is:
import { ApiHideProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import {
IsEmpty,
IsEnum,
IsMongoId,
...
1
vote
1
answer
3k
views
How to validate nested plain objects by a sub-DTO with class-validator, class-transformer in NestJS
I've been investigating the topic for a long time. I see the ready solution is
absent that works well in NestJS because transformation does not work before validation. If we enable transformation in ...
1
vote
1
answer
1k
views
class-validator with nestjs prevent creating missing fields with undefined when used with @IsOptional() decorator
I have a DTO that looks like this:
export class UpdateXXXDto {
@IsString()
@IsNotEmpty()
field1: string;
@IsOptional()
@IsString()
field2: string;
@IsOptional()
@IsString()
field3: ...
1
vote
0
answers
262
views
How to validate object using class-validator again after receive from @Body() of nestjs?
I try this approach but when I enter input that shouldn't pass when validate it return []
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { MyDTO } ...
1
vote
1
answer
1k
views
Can @Headers in Nest.js be validated through DTOs?
I am new to Nest.js and have a good understanding of the overall syntax. However, while creating one of the controllers, I encountered an issue related to the validation of data parsed by the @Headers ...
0
votes
1
answer
114
views
Nestjs Decorator check at least one attribute is accepted
Maybe I don't understand the DTO, but I want it to check if at least one attribute is sent by the request. How can I do it?
Here is my dto:
//import libs
export class WorkspaceDto {
@IsString()
...