Open lothern opened 4 years ago
Ok, I've been able to resolve my issue by modifying request-query.builder.ts query method to pass some more options to the required qs stringify method.
Before example from request-query.builder.ts:
query(encode = true): string {
if (this.queryObject[this.paramNames.search]) {
this.queryObject[this.paramNames.filter] = undefined;
this.queryObject[this.paramNames.or] = undefined;
}
this.queryString = stringify(this.queryObject, { encode });
return this.queryString;
}
After example from request-query.builder.ts:
query(encode = true): string {
if (this.queryObject[this.paramNames.search]) {
this.queryObject[this.paramNames.filter] = undefined;
this.queryObject[this.paramNames.or] = undefined;
}
this.queryString = stringify(this.queryObject, { encode, indices: false });
return this.queryString;
}
Which results in this query string:
"?join=Entity1&join=Entity2&join=Entity3"
Is this something I should submit a pull request for? Is anyone else experiencing this issue?
Any thoughts?
@lothern can I ask you why you don't want an indexed array here?
Of course you may!
The indexed array query string isn't parsed by the nestjsx/crud-typeorm & nestjsx/crud packages. That is to say I don't get a "joined" response from my backend running those two packages.
Even the crud/crud-typeorm documentation states that the query string for joins doesn't have array indices:
do you use the latest crud
and crud-typeorm
packages?
because this functionality is already covered by tests and I hadn't any fails here. Also, I've tested it manually and also hadn't any issues with that :(
Yes, I'm using @nestjsx/crud@4.4.1, @nestjsx/crud-typeorm@4.4.1, and @nestjsx/crud-request@4.4.1
I appreciate you looking into this.
I have the same issue on filtering it adds filter[0]=name||eq||imbecilic&filter[0]=status||eq||active
gives me a 400 - Bad Request if i delete the indexed array from the string everything works and i get the desired result.
Thanks for your effort!
Yeah, it appears that the version of qs that crud-request depends on should be passed the indices: false option to output the correct query string for the crud & crud-typeorm packages to parse correctly.
@ImBeCiliC Have you attempted modifying the crud-request request-query.builder.js file's query function to pass the indices: false option to qs? That worked for me.
I'm curious if this is happening for more people.
add %5B0%5D is broken my search result ....
@zieglar Were you able to resolve your broken search with any of the methods described above?
after .query()
loop for .replace(%5B${i}%5D
, '')
and again .replace('%5B%5D', '').replace('[]', '')
Team,
I've encountered an issue with the crud-request 4.4.1 package. I'm likely doing something wrong and a few days worth of searching has turned up zero results.
I'm getting array indices included in the query string from the RequestQueryBuilder object.
Example:
Results in this query string:
I've also done this:
With this result:
I've been unable to find another way to remove the array indices from the resulting query string other than doing a regex string replacement. What am I missing?