kurierjs / kurier

TypeScript framework to create JSON:API compliant APIs
https://kurier.readthedocs.io/en/latest/
MIT License
61 stars 9 forks source link

fix/multiple.includes.nestedResources #373

Closed Martinarbez closed 10 months ago

Martinarbez commented 10 months ago

This Pull Request introduces several changes to address a key issue and improve the functionality and testing of the application:

Problem Solved: The application was previously unable to handle queries for a resource with multiple nested resources simultaneously. If multiple nested resources were included in the query, only the last one was returned. This issue has been resolved with the changes in this PR.

  1. Enhancement in knex-processor.ts: The parseOperationIncludedRelationships function has been updated to ensure that the acumRelationships object correctly accumulates relationships without overwriting existing ones. This is achieved by spreading the existing relationships before adding a new one. This change is part of the solution to the problem described above.

  2. Refactoring in serializer.ts: The serialization process has been simplified. Previously, the code was creating a new array with unique type_id combinations from includedData and then mapping over this array to find the corresponding items in includedData. This has been replaced with a direct return of includedData, which simplifies the code and may improve performance.

  3. Addition of a new test in nestedResources.test.ts: A new test has been added to verify the correct retrieval of the first article's author's votes and comments. This test will help ensure that the application's data retrieval and serialization processes are working as expected, and that multiple nested resources can be retrieved simultaneously.