Skip to content

Commit

Permalink
PB-33447 - Ensure EntityV2Collection is treating items at the abstrac…
Browse files Browse the repository at this point in the history
…t constructor level
  • Loading branch information
cedricalfonsi committed May 13, 2024
1 parent 32a9f4c commit 373df9a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passbolt-styleguide",
"version": "4.8.0-alpha.8",
"version": "4.8.0-alpha.9",
"license": "AGPL-3.0",
"copyright": "Copyright 2023 Passbolt SA",
"description": "Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.",
Expand Down
18 changes: 18 additions & 0 deletions src/shared/models/entity/abstract/entityV2Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,29 @@ class EntityV2Collection extends EntityCollection {
/**
* Retrieve the entity class this collection is handling
* @return {Class}
* @abstract
*/
get entityClass() {
throw new Error("The collection class should declare the entity class that is handled.");
}

/**
* @inheritDoc
* The EntityV2 collection will push the dtos into the collection.
* @throws {EntityCollectionError} If a item does not validate its entity schema.
* @throws {EntityCollectionError} If a item does not validate the collection validation build rules.
*/
constructor(dtos = [], options = {}) {
super(dtos, options);
/*
* Push the items into the collection.
* Use the the _props property where EntityCollection V1 clone the dtos into.
* Delete it after usage.
*/
this.pushMany(this._props, {...options, clone: false});
this._props = null;
}

/**
* Build or clone entity.
* @param {object|Entity} data The data of the item to push
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ export class TestEntityV2Collection extends EntityV2Collection {
return TestEntity;
}

constructor(dto, options = {}) {
super(EntitySchema.validate(TestEntityV2Collection.name, dto, TestEntityV2Collection.getSchema()), options);
this.pushMany(this._props, {...options, clone: false});
this._props = null;
constructor(dtos = [], options = {}) {
dtos = EntitySchema.validate(TestEntityV2Collection.name, dtos, TestEntityV2Collection.getSchema());
super(dtos, options);
}

/**
Expand Down

0 comments on commit 373df9a

Please sign in to comment.