diff options
author | Marius David Wieschollek <passwords.public@mdns.eu> | 2020-02-08 15:10:49 +0300 |
---|---|---|
committer | Marius David Wieschollek <passwords.public@mdns.eu> | 2020-02-08 15:10:49 +0300 |
commit | fb8f5db8539f4b26371eba6f876f3d1fbfede7c0 (patch) | |
tree | f4317a675afde89c38eb434142ccb490d105d077 /src | |
parent | f85dc2de525a0b8824c98069d56618cb93808610 (diff) |
Added settings model
Signed-off-by: Marius David Wieschollek <passwords.public@mdns.eu>
Diffstat (limited to 'src')
-rw-r--r-- | src/Exception/InvalidScopeError.js | 5 | ||||
-rw-r--r-- | src/Model/Setting/Setting.js | 151 | ||||
-rw-r--r-- | src/Repositories/SettingRepository.js | 77 |
3 files changed, 233 insertions, 0 deletions
diff --git a/src/Exception/InvalidScopeError.js b/src/Exception/InvalidScopeError.js new file mode 100644 index 0000000..fa0d58d --- /dev/null +++ b/src/Exception/InvalidScopeError.js @@ -0,0 +1,5 @@ +export default class InvalidScopeError extends Error { + constructor(scope) { + super(`Invalid scope ${scope}`); + } +}
\ No newline at end of file diff --git a/src/Model/Setting/Setting.js b/src/Model/Setting/Setting.js new file mode 100644 index 0000000..3a73bdb --- /dev/null +++ b/src/Model/Setting/Setting.js @@ -0,0 +1,151 @@ +import InvalidScopeError from '../../Exception/InvalidScopeError'; + +export default class Setting { + + /** + * @return {String} + */ + get SCOPE_USER() { + return 'user'; + } + + /** + * @return {String} + */ + get SCOPE_SERVER() { + return 'server'; + } + + /** + * @return {String} + */ + get SCOPE_CLIENT() { + return 'client'; + } + + /** + * @return {String[]} + */ + get SCOPES() { + return [ + this.SCOPE_USER, + this.SCOPE_SERVER, + this.SCOPE_CLIENT + ]; + } + + /** + * @return {String} + */ + get name() { + return this._name; + } + + /** + * @param {String} value + */ + set name(value) { + this._name = value; + } + + /** + * @return {String} + */ + get value() { + return this._value; + } + + /** + * @param {String} value + */ + set value(value) { + this._value = value; + } + + /** + * @return {String} + */ + get scope() { + return this._scope; + } + + /** + * @param {String} value + */ + set scope(value) { + if(this.SCOPES.indexOf(value) === -1) { + throw new InvalidScopeError(value); + } + + this._scope = value; + } + + /** + * @param {String} name + * @param {String} value + * @param {String} scope + */ + constructor(name, value, scope = 'client') { + if(this.SCOPES.indexOf(scope) === -1) { + throw new InvalidScopeError(scope); + } + + this._name = name; + this._value = value; + this._scope = scope; + } + + /** + * @return {String} + */ + getName() { + return this._name; + } + + /** + * @param {String} value + * + * @return {Setting} + */ + setName(value) { + this.name = value; + + return this; + } + + /** + * @return {String} + */ + getValue() { + return this._value; + } + + /** + * @param {String} value + * + * @return {Setting} + */ + setValue(value) { + this.value = value; + + return this; + } + + /** + * @return {String} + */ + getScope() { + return this._scope; + } + + /** + * @param {String} value + * + * @return {Setting} + */ + setScope(value) { + this.scope = value; + + return this; + } +}
\ No newline at end of file diff --git a/src/Repositories/SettingRepository.js b/src/Repositories/SettingRepository.js new file mode 100644 index 0000000..c24f63c --- /dev/null +++ b/src/Repositories/SettingRepository.js @@ -0,0 +1,77 @@ +export default class SettingRepository { + + /** + * + * @param {Api} api + */ + constructor(api) { + this._api = api; + /** @type Cache **/ + this._cache = api.getInstance('cache.cache'); + /** @type AbstractConverter **/ + //this._converter = api.getInstance(`converter.setting`); + } + + /** + * + * @return {AbstractRepository} + */ + clearCache() { + this._cache.clear(); + + return this; + } + + findAll() { + let request = this._api.getRequest() + .setPath(`1.0/settings/list`); + } + + findByScope(scope) { + let request = this._api.getRequest() + .setPath(`1.0/settings/list`) + .setData([scope]); + } + + findByScopes(scopes) { + let request = this._api.getRequest() + .setPath(`1.0/settings/list`) + .setData([scopes]); + } + + async findByName(name) { + let data = await this._api.getRequest() + .setPath(`1.0/settings/get`) + .setData([name]) + .send(); + } + + findByNames(names) { + let request = this._api.getRequest() + .setPath(`1.0/settings/get`) + .setData(names); + } + + set(setting) { + let request = this._api.getRequest() + .setPath(`1.0/settings/set`) + .setData(setting); + } + + reset(setting) { + let request = this._api.getRequest() + .setPath(`1.0/settings/reset`) + .setData(setting); + } + + /** + * + * @param {Object} data + * @returns {Promise<AbstractRevisionModel>} + * @private + */ + async _dataToModel(data) { + + return model; + } +}
\ No newline at end of file |