oa-jira
Version:
Octet Agile's JIRA connectivity project.
51 lines (42 loc) • 1.79 kB
JavaScript
const commons = require('../../commons');
const constants = require('../constants');
class Type {
#id;
#name;
#description;
#iconUrl;
#subtask;
#hierarchyLevel;
constructor({ id, description, iconUrl, name, subtask, hierarchyLevel } = {}) {
this.#id = commons.string.check(id, constants.types.settings.id);
this.#name = commons.string.check(name, constants.types.settings.name);
this.#description = commons.string.check(description, constants.types.settings.description);
this.#iconUrl = commons.string.check(iconUrl, constants.types.settings.iconUrl);
this.#subtask = commons.boolean.check(subtask, constants.types.settings.subtask);
this.#hierarchyLevel = commons.int.check(hierarchyLevel, constants.types.settings.hierarchyLevel);
}
getId = () => this.#id;
getName = () => this.#name;
getDescription = () => this.#description;
getIconUrl = () => this.#iconUrl;
isSubTask = () => this.#subtask;
getHierarchyLevel = () => this.#hierarchyLevel;
toString = () => `Type[${this.#name} #${this.#id}]`;
toJSON = () => {
const json = { id: this.#id, name: this.#name, subtask: !!this.#subtask, hierarchyLevel: this.#hierarchyLevel };
if (this.#description) json.description = this.#description;
if (this.#iconUrl) json.iconUrl = this.#iconUrl;
return json;
};
static check(type) {
return commons.object.check(type, { name: 'type', className: 'Type', _class: Type });
}
static create({ id, description, iconUrl, name, subtask, hierarchyLevel } = {}) {
try {
return Promise.resolve(new Type({ id, description, iconUrl, name, subtask, hierarchyLevel }));
} catch (error) {
return Promise.reject(error);
}
}
}
module.exports = Type;