diff options
author | Marius David Wieschollek <passwords.public@mdns.eu> | 2020-02-26 20:27:37 +0300 |
---|---|---|
committer | Marius David Wieschollek <passwords.public@mdns.eu> | 2020-02-26 20:27:37 +0300 |
commit | a0ac896fa0be99cdf6f866bdc67d47803acb3dc1 (patch) | |
tree | 9e21b5bea384457b1bd613092e834ae20b0b199b | |
parent | 44dc505f5a92427bda2cb74a7b9f40ff16c8f592 (diff) |
Allow fetching single items from collection
Signed-off-by: Marius David Wieschollek <passwords.public@mdns.eu>
-rw-r--r-- | src/Api/Api.js | 4 | ||||
-rw-r--r-- | src/Collection/AbstractCollection.js | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/Api/Api.js b/src/Api/Api.js index be87216..84d7892 100644 --- a/src/Api/Api.js +++ b/src/Api/Api.js @@ -181,7 +181,7 @@ export default class Api { * @returns {SessionAuthorization} */ getSessionAuthorization() { - return this.getInstance('authorization.session', this); + return this.getInstance('authorization.session'); } /** @@ -333,7 +333,7 @@ export default class Api { response: ApiResponse }, authorization: { - session: SessionAuthorization + session: () => { return new SessionAuthorization(this); } }, challenge : { pwdv1: PWDv1Challenge diff --git a/src/Collection/AbstractCollection.js b/src/Collection/AbstractCollection.js index 5947cf4..4dd63a4 100644 --- a/src/Collection/AbstractCollection.js +++ b/src/Collection/AbstractCollection.js @@ -3,6 +3,13 @@ import AbstractModel from '../Model/AbstractModel'; export default class AbstractCollection { /** + * @return {Number} + */ + get length() { + return this._elements.length; + } + + /** * * @param {AbstractConverter} converter * @param {AbstractModel} elements @@ -60,6 +67,23 @@ export default class AbstractCollection { } /** + * @param {(Number|String)} index + * @return {AbstractModel|string|null} + * @api + */ + get(index) { + if(this._elements.hasOwnProperty(index)) { + return this._elements[index]; + } + + for(let element in this._elements) { + if(element.getId() === index) return element; + } + + return null; + } + + /** * @param {(String|Object|AbstractModel)} element * @private */ |