Url query resolver for @Controller methods
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
With the current implementation, there is no easy way to filter data through url query string.
Expected behavior
Empowering Controllers the ability to resolve url querys & building an apropiate SelectQuery
using TypeORM QueryBuilder
.
@Controller('foo')
export class FooController {
@Get()
@Filterable()
filter(@ORMQuery() query //A SelectQuery built) {
// Call Provider here. In order to simplify the example I'll call Repository directly
return this.fooRepository.find(query);
}
}
Given a query string like:
foo/?name=foo&surname__contains=fake&fk__related_prop=2&page=2
It will return the following SelectQuery
:
const filterQuery = await connection
.getRepository(Foo)
.createQueryBuilder('foo')
.where('foo.name = foo')
.andWhere('surname like fake')
.innerJoinAndSelect(Foo, 'foo', 'foo.related_prop = 2')
.take(25)
.skip(25 * 2 - 1)
Update 02/27/2019
I found this library whose owner is @bashleigh that resolves pagination & limit problem (and filterParameters, right).
Could it be interesting to implement proposed feature in this library? Parsing query string and transform it like TypeORM findOptions
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
A very common use case is to be able to filter content for an endpoint using the url query format.
Environment
Nest version: @next
Others:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:6
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
A resolver is a function that's responsible for populating the data for a single field in your schema. It can populate that data...
Read more >Routing to controller actions in ASP.NET Core - Microsoft Learn
Learn how ASP.NET Core MVC uses Routing Middleware to match URLs of incoming requests and map them to actions.
Read more >How to configure query parameters in Spring Controllers
In this post, we will discuss what query parameters are and how to configure them in a Spring controller using the @RequestParam annotation....
Read more >Custom Web Controller Arguments with Spring MVC and ...
Spring MVC provides a very convenient programming model for creating web controllers. We declare a method signature and the method arguments ...
Read more >MVC: How to correctly resolve Url property in Controller?
But in some cases I need to resolve the URL in a Controller, so I use UrlResolver.Current.GetUrl. Howerver, the resulting friendly url still...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update:
I publish this package that allows transform Express req.query into TypeORM queries. For now, doesn’t allow join/nested props queries, but it will coming soon 😃
If you consider interesting adding it as a
nestjs/typeorm
feature, I could integrate on it maybe like:@rjlopezdev please also check some similar work here https://github.com/nestjsx/crud