Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save and find nested entities #37

Merged
merged 27 commits into from Aug 22, 2023

Conversation

vitorgamer58
Copy link
Contributor

@vitorgamer58 vitorgamer58 commented Jul 10, 2023

This pull request aims to implement a feature that will allow inserting and finding entities that contain fields that are entities (or array of entities), which in this context, I called nested entities.
This is related to issue #35
I also added export DataMapper class in Herbs2Mongo.js to allow developer to extend this class and create their own custom DataMapper.
I'm already covering a previous case reported in the issue, in which the collection was missing in the database containing the meta field that is inherited from BaseEntity, however, I'm not covering the errors field, which for now can be covered by developers simply doing a delete on the object before calling the find method, as this is a feature that will be addressed in the issue: herbsjs/gotu#71
These changes do not implement breaking changes.

Proposed Changes

  1. Adjusts collectionFieldsWithValues method to save nested entities
  2. Adjusts collectionFields method to not remove entities
  3. Adjust buildProxy to maps the entity's internal fields and returns an object with these fields filled in
  4. Improved empty object checking in arrayDataParse
  5. Enable export of DataMapper class

Screenshots

Nested entity in find method return:
Find
Nested entity that was saved to the database:
MongoDB Compass

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • Remember to check if code coverage decrease, if so, please implement the necessary tests

Reviewing Maintainer

  • Label as breaking if this is a large fundamental change
  • Label as either automation, bug, documentation, enhancement, infrastructure, or performance

…d undefined handling

collectionFieldsWithValues method modified to work with nested entities, filter null and undefined
extracted to a method.
collectionFields method modified
to not remove entities
…ntities

Tests for the modifications to the collectionFieldsWithValue and collectionFields methods, which now
do not remove nested entities.
Adjust buildProxy to not return undefined when isEntity is true
Validates that fields are being converted to entities when they are nested.
An object passed to arrayDataParse can be null or undefined, so checking has been improved using the
checker.
Adjust unit tests referring to entity array when value is empty.
src/dataMapper.js Outdated Show resolved Hide resolved
Copy link
Contributor

@jhomarolo jhomarolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests in testDB folder before the full review

Maps the entity's internal fields and returns an object with these fields filled in.
Adds and Modifies existing tests to validate nested entities.
@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #37 (091670e) into main (bc60fda) will increase coverage by 1.31%.
Report is 5 commits behind head on main.
The diff coverage is 100.00%.

❗ Current head 091670e differs from pull request most recent head 1122dd1. Consider uploading reports for the commit 1122dd1 to get more accurate results

@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   94.50%   95.81%   +1.31%     
==========================================
  Files           3        3              
  Lines         182      239      +57     
==========================================
+ Hits          172      229      +57     
  Misses         10       10              
Files Changed Coverage Δ
src/dataMapper.js 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vitorgamer58
Copy link
Contributor Author

Please add tests in testDB folder before the full review

Valid, added tests referring to nested entities in the findById file.

…efined

Extract filter of null and undefined to `isNotNullOrUndefined`
Refactor and change name of
`filterNullAndUndefined` function
Update `collectionFieldsWithValue` to use new function structure
Segregate entity parsing logic into `parseEntity` function
Must contain a children key containing an array of files when the field is entity
Recursion makes it possible to work with entities nested at multiple levels
Recursive parsing of nested entities allows multi-level nested objects to be parsed from the
collection
Must be able to return an array of nested entities with multiple fields
@vitorgamer58 vitorgamer58 force-pushed the feat/save-and-find-nested-entities branch from adcc9cb to 3896da7 Compare August 20, 2023 05:10
When entity.type is an array, it must check if the item inside the array is an entity (extends
BaseEntity)
@dalssoft dalssoft merged commit a6ef5c6 into herbsjs:main Aug 22, 2023
3 checks passed
@herbsjs-robot
Copy link

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Already in production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants