How to apply both ValidationPipe() and ParseIntPipe() to params?

If you apply the ParseIntPipe to the id param, it will only transform id but not the property id of params, here it will stay a string. Instead, you can use class-transformer to transform your param to a number: import { Transform } from ‘class-transformer’; export class CreateDataParams { @Transform(id => parseInt(id), {toClassOnly: true}) id: … Read more

Class-validator – validate array of objects

Add @Type(() => AuthParam) to your array and it should be working. Type decorator is required for nested objects(arrays). Your code becomes import { IsArray, ValidateNested, ArrayMinSize, ArrayMaxSize } from ‘class-validator’; import { AuthParam } from ‘./authParam.model’; import { Type } from ‘class-transformer’; export class SignInModel { @IsArray() @ValidateNested({ each: true }) @ArrayMinSize(2) @ArrayMaxSize(2) @Type(() … Read more

TypeORM Entity in NESTJS – Cannot use import statement outside a module

My assumption is that you have a TypeormModule configuration with an entities property that looks like this: entities: [‘src/**/*.entity.{ts,js}’] or like entities: [‘../**/*.entity.{ts,js}’] The error you are getting is because you are attempting to import a ts file in a js context. So long as you aren’t using webpack you can use this instead so … Read more

Inject TypeORM repository into NestJS service for mock data testing

Let’s assume we have a very simple service that finds a user entity by id: export class UserService { constructor(@InjectRepository(UserEntity) private userRepository: Repository<UserEntity>) { } async findUser(userId: string): Promise<UserEntity> { return this.userRepository.findOne(userId); } } Then you can mock the UserRepository with the following mock factory (add more methods as needed): // @ts-ignore export const repositoryMockFactory: … Read more

Why are cookies not sent to the server via getServerSideProps in Next.js?

That’s because the request inside getServerSideProps doesn’t run in the browser – where cookies are automatically sent on every request – but actually gets executed on the server, in a Node.js environment. This means you need to explicitly pass the cookies to the axios request to send them through. export async function getServerSideProps({ req }) … Read more