lucasrochagit / nest-mongo-query-parser

A MongoDB query string parser to be used in applications developed with NestJS.
Apache License 2.0
12 stars 8 forks source link

Empty string search #5

Closed EniotnaTennob closed 1 year ago

EniotnaTennob commented 1 year ago

Hello @lucasrochagit Sorry if the question may seem stupid but how can I search on an empty string image thank you in advance

EniotnaTennob commented 1 year ago

maybe by changing this part of the code ? image

lucasrochagit commented 1 year ago

Hi @EniotnaTennob!

Your question doesn't seem stupid, on the contrary, it's quite interesting.

I hadn't thought of this use case when I built the library. For this type of query works properly, I would need to consider an empty query value as valid.

There are many adjustments to be made to this library, but unfortunately I'm not having much time to maintain it.

For this case, so that values such as empty strings can be accepted, I need to change the following code snippet:

// src/lib/query/mongo.query.ts, line 165
function getSimpleFilterValue(
  filter: string
): string | number | boolean | Date | object | null {
  if (!filter) return null;

It should be:

// src/lib/query/mongo.query.ts, line 165
function getSimpleFilterValue(
  filter: string
): string | number | boolean | Date | object | null {
  if (filter === null || filter === undefined) return null;

Or:

// src/lib/query/mongo.query.ts, line 165
function getSimpleFilterValue(
  filter: string
): string | number | boolean | Date | object | null {
   if (filter === "" ) return filter;
   if (!filter) return null;

To perform this update, I need to develop some tests as well, to ensure that this change does not negatively impact the library's functionality. If you want to send a PR, containing the update and tests, I would be happy with your contribution. But I will talk to my friend, who maintains the library with me, to see if he can perform this feature.

EniotnaTennob commented 1 year ago

Hi @lucasrochagit Thank you for your quick reply, I try to post a PR ASAP. Best regards