SoftwareBrothers / adminjs-mongoose

Mongoose adapter for AdminJS
MIT License
14 stars 39 forks source link

List action returns both records with status Active and Inactive when search only for Active #105

Open geekyayush opened 1 year ago

geekyayush commented 1 year ago

I have a number of records in my collection; some have "Active" in status property and others have "Inactive".

In AdminJS frontend, when I filter status field to show me only "Active" status records, it returns both Active and Inactive. For Inactive status filter, it works fine.

I believe the reason could be in file "src/utils/convert-filter.ts", line number 19. Link; https://github.com/SoftwareBrothers/adminjs-mongoose/blob/master/src/utils/convert-filter.ts#L19

It's searching a property using regex, which returns both Active and Inactive since both values contain "Active".

Is there any workaround we can do to make sure only either Active or Inactive records get returned by the list action?

hiteshbedre commented 1 year ago

You can use symbols such as ^ and $ while regex matching.

^ asserts position at start of a line $ asserts position at the end of a line

so the final pattern becomes: ^Active$

Here is the playground: https://regex101.com/r/QUhCxQ/1