nestjs-paginate icon indicating copy to clipboard operation
nestjs-paginate copied to clipboard

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

Open arvindsedha opened this issue 3 years ago • 1 comments

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);

arvindsedha avatar Nov 01 '21 10:11 arvindsedha

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 :)

ppetzold avatar Nov 01 '21 11:11 ppetzold