e-Spirit / javascript-content-api-library

Apache License 2.0
7 stars 11 forks source link

filterByValue: checking for null value is not possible #169

Closed re-kfa closed 11 months ago

re-kfa commented 1 year ago

Hi,

when using fetchByFilter it is not possible to compare against null.

For example:

fsxaApi.fetchByFilter({
  filters: [
    {
        field: "entityType",
        operator: ComparisonQueryOperatorEnum.EQUALS,
        value: "news",
      },
      {
        field: "formData.tt_start.value",
        operator: ComparisonQueryOperatorEnum.NOT_EQUALS,
        value: null,
      },
  ],
})

The problem is that at this line https://github.com/e-Spirit/fsxa-api/blob/fb65a1ede599a0b3fe8c2271401355ee01b82cfa/src/modules/QueryBuilder.ts#L92 filter.value is checked with the !-operator which is true for a null-value.

When reading through Mongo-DB documentation this is the correct way to check for a null-value. https://www.mongodb.com/docs/manual/tutorial/query-for-null-fields/

So I suggest to change the check for filter.value to !("value" in filter) or typeof filter.value === 'undefined' as this only checks if the property value is existing on the object filter.

deangite commented 11 months ago

Hello,

I'm pleased to inform you that the issue you reported regarding the fetchByFilter function has been successfully addressed and resolved. The problem you encountered when comparing against null values has been rectified in the codebase.

The root cause was identified in the QueryBuilder.ts file where null values were being checked using an incorrect approach. The solution involves modifying the way null values are handled within the code.

The implementation to fix this issue can be found in the following pull request (PR): GitHub PR #172. In this PR, you will find the changes that have been made to the code to accurately handle null value comparisons in line with the MongoDB documentation.

Thank you for bringing this issue to our attention, and we appreciate your patience throughout the resolution process. If you have any further questions or feedback, please don't hesitate to reach out.