@publidata/utils-data-manager
Version:
Collection of methods to extract data from publidata
70 lines (59 loc) • 1.44 kB
JavaScript
const isEmpty = require("lodash/isEmpty");
const { getRedirection } = require("@publidata/utils-mapper");
const PublidataObject = require("../");
/**
* Class representing a service.
* @extends PublidataObject
*/
class PublidataObjectService extends PublidataObject {
/**
* @return {Object}
*/
get parent() {
const { parent } = this.object._source;
return this.memoize("parent", parent);
}
/**
* @return {String}
*/
get name() {
const { name } = this.object._source;
return this.memoize("name", name);
}
/**
* @return {String}
*/
get icon() {
const { icon } = this.object._source.metas;
return this.memoize("icon", icon);
}
/**
* @return {String}
*/
get color() {
const { color } = this.object._source.metas;
if (color) return this.memoize("color", color);
return this.memoize("color", "var(--primary)");
}
/**
* @return {Array}
*/
get children() {
const { children } = this.object._source;
return this.memoize("children", children);
}
/**
* @return {Array}
*/
get alerts() {
const { alerts } = this.object._source;
return this.memoize("alerts", alerts);
}
get hasServiceables() {
return this.memoize("hasServiceables", !isEmpty(this._source.serviceables));
}
get isRedirected() {
return this.memoize("isRedirected", !!getRedirection(this));
}
}
module.exports = PublidataObjectService;