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

How to use nestjs-paginate with limiting the query fields results? #114

Closed
arvindsedha opened this issue Nov 1, 2021 · 1 comment
Closed
Labels
enhancement New feature or request will accept PR

Comments

@arvindsedha
Copy link

is there a way to defind /cats?fields=field1,field2 etc? ats the movement even using some custom solution?

E.g. provide also somehow FindOneOptions options when calling

paginate(query, this.repository, config);

@ppetzold
Copy link
Owner

ppetzold commented Nov 1, 2021

Doesn't currently exist for repositories. You could use QueryBuilder as a workaround.

But..

Allowing query to pass fields onto FindOptions would probably be an easy and straightforward solution.

Helper config:

paginate(query, this.usersRepository, {
    sortableColumns: ['id', 'username', 'email', 'created'],
    select: ['id', 'username', 'email', 'firstName', 'lastName', 'created']
})

Select may acts as a whitelist for the query string here as well.

Query string:

/users?select=email,created

PK might be always selected.

Happy to accept PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request will accept PR
Projects
None yet
Development

No branches or pull requests

2 participants