UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

48 lines (38 loc) 1.44 kB
const commons = require('../../commons'); const constants = require('../constants'); class Category { #id; #key; #colorName; #name; constructor({ id, key, colorName, name } = {}) { this.#id = commons.int.check(id, constants.categories.settings.id); this.#key = commons.string.check(key, constants.categories.settings.key); this.#colorName = commons.string.check(colorName, constants.categories.settings.colorName); this.#name = commons.string.check(name, constants.categories.settings.name); } getId = () => this.#id; getKey = () => this.#key; getColorName = () => this.#colorName; getName = () => this.#name; toString = () => `Category[${this.#name} #${this.#id}]`; toJSON = () => { const json = { id: this.#id, key: this.#key, name: this.#name }; if (this.#colorName) json.colorName = this.#colorName; return json; }; static check(category) { return commons.object.check(category, { name: 'category', className: 'Category', _class: Category }); } static resolve(category) { return commons.object.resolve(category, { name: 'category', className: 'Category', _class: Category }); } static create({ id, key, colorName, name } = {}) { try { return Promise.resolve(new Category({ id, key, colorName, name })); } catch (error) { return Promise.reject(error); } } } module.exports = Category;