Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestJS decorators stop working if a module with Paginate decorator isn't imported first #864

Open
renatosantos0611 opened this issue Jan 30, 2024 · 3 comments

Comments

@renatosantos0611
Copy link

renatosantos0611 commented Jan 30, 2024

I don't know if nestjs-paginate should work like this, but all controllers of any Module that don't have any Paginate decorators give undefined value in nestjs decorators like @Body, @param, @query and @Req ... when import first than Module that have Paginate decorators, I create a simple example of that

import { Controller, Get } from '@nestjs/common';
import { Paginate, PaginateQuery } from 'nestjs-paginate';

@Controller('with-paginate')
export class WithPaginateController {
  @Get()
  findAll(@Paginate() query: PaginateQuery) {
    return query;
  }
}
import { Body, Controller, Get, Param, Post } from '@nestjs/common';

@Controller('without-paginate')
export class WithoutPaginateController {
  @Post()
  create(@Body() body: any) {
    return body;
  }

  @Get(':id')
  findAll(@Param('id') id: string) {
    return id;
  }
}

in a app.module.ts

import { Module } from '@nestjs/common';
import { WithoutPaginateModule } from './without-paginate/without-paginate.module';
import { WithPaginateModule } from './with-paginate/with-paginate.module';

@Module({
  imports: [WithoutPaginateModule, WithPaginateModule],
})
export class AppModule {}

WithoutPaginateModule imports first than WithPaginateModule, so all nestjs decorators from WithoutPaginateModule controllers get undefined value, importing WithPaginateModule first, everything works. Should the sequence of imports really matter? Did I forget something?

here example https://github.com/renatosantos0611/nestjs-paginate-query-issue

Thanks for help ;D

@Helveg
Copy link
Collaborator

Helveg commented Mar 3, 2024

Please take a look at the README: https://github.com/ppetzold/nestjs-paginate?tab=readme-ov-file#code

In there you can see that there are 2 steps:

  1. In the controller, you MUST apply the @Paginate() query: PaginateQuery parameter decorator.
  2. You MUST use the paginate function, passing it the query, repository, and pagination configuration.

Your code does not seem to have these steps implemented properly. Feel free to ask more questions! :)

@renatosantos0611
Copy link
Author

Please take a look at the README: https://github.com/ppetzold/nestjs-paginate?tab=readme-ov-file#code

In there you can see that there are 2 steps:

  1. In the controller, you MUST apply the @Paginate() query: PaginateQuery parameter decorator.
  2. You MUST use the paginate function, passing it the query, repository, and pagination configuration.

Your code does not seem to have these steps implemented properly. Feel free to ask more questions! :)

I think you didn't understand the problem or maybe I didn't convey it clearly, I use this lib in all my projects and works good, but you can try it yourself or use my example, you need only to create a Module containing controllers without using this lib, and make that Module import first in your main Module, and see every controllers of your entire application that don't use this lib stopping work.

@Helveg
Copy link
Collaborator

Helveg commented Mar 8, 2024

Ok, could you show your example as a complete minimal reproducible example? I'll link an explanation on MREs https://stackoverflow.com/help/minimal-reproducible-example

In its current form I can't tell what you mean from the code, and a text description of code is hard to follow 😅

you need only to create a Module containing controllers without using this lib, and make that Module import first in your main Module, and see every controllers of your entire application that don't use this lib stopping work.

Could you do this for me and share a link to the repository, so that I can execute the code and see it in action? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants