UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

52 lines (43 loc) 1.73 kB
const commons = require('../../commons'); const constants = require('../constants'); const Category = require('../classes/category.class'); class Status { #id; #description; #iconUrl; #name; #category; constructor({ id, description, iconUrl, name, category } = {}) { this.#id = commons.string.check(id, constants.statuses.settings.id); this.#name = commons.string.check(name, constants.statuses.settings.name); this.#description = commons.string.check(description, constants.statuses.settings.description); this.#iconUrl = commons.string.check(iconUrl, constants.statuses.settings.iconUrl); this.#category = Category.check(category); } getId = () => this.#id; getDescription = () => this.#description; getIconUrl = () => this.#iconUrl; getName = () => this.#name; getCategory = () => this.#category; toString = () => `Status[${this.#name} #${this.#id}]`; toJSON = () => { const json = { id: this.#id, name: this.#name, category: this.#category.toJSON() }; if (this.#iconUrl) json.iconUrl = this.#iconUrl; if (this.#description) json.description = this.#description; return json; }; static check(status) { return commons.object.check(status, { name: 'status', className: 'Status', _class: Status }); } static resolve(status) { return commons.object.resolve(status, { name: 'status', className: 'Status', _class: Status }); } static create({ id, description, iconUrl, name, category } = {}) { try { return Promise.resolve(new Status({ id, description, iconUrl, name, category })); } catch (error) { return Promise.reject(error); } } } module.exports = Status;