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

use select for filter returning result but by default return all result #1025

Open
mortezakarimi opened this issue Nov 11, 2024 · 2 comments

Comments

@mortezakarimi
Copy link

Current implementation needs to define select properties to use select in query params
I want to get all available properties but when I need to select some fields use select in query params and return selected properties
I have a big entity with many fields and relations and most of the time I need all results but in some cases like "select inputs" I just need the id and name, I cannot use the select param until I define explicitly select the property in the configuration

@Helveg
Copy link
Collaborator

Helveg commented Nov 13, 2024

Could you explain with code examples what the problem/behaviour is that you want?

@mortezakarimi
Copy link
Author

  static readonly PAGINATION_CONFIG: PaginateConfig<Project> = {
    sortableColumns: ['createdAt'],
    searchableColumns: ['name', 'serial'],
    nullSort: 'last',
    defaultSortBy: [['createdAt', 'DESC']],
    relations: [
      'a',
      'b',
      'a.a',
      'c',
      'c.a',
      'c.b',
      'd',
      'e',
      'f',
    ],
    filterableColumns: {},
  };

  async findAll(query: PaginateQuery) {
    return paginate(
      query,
      this.projectRepository,
      Service.PAGINATION_CONFIG,
    );
  }

currently, with the above config, we can get all information we need but in some cases we need to select only some properties. As you can see information we need is too much with relations so I can't specify select property in the pagination config

I want to use a query something like the following

/api/projects?page=1&limit=20&select[]=id&select[]=name

to only select ID and name, but with the current implementation, we should specify selectable fields in the configuration to able to use select in query params

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