UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

55 lines (45 loc) 1.81 kB
const commons = require('../../commons'); const constants = require('../constants'); class BoardColumn { #name; #order; #min; #max; #statusIds; constructor({ name, order, min, max, statusIds = [] } = {}) { this.#name = commons.string.check(name, constants.boards.columns.settings.name); this.#order = commons.int.check(order, constants.boards.columns.settings.order); this.#min = commons.int.check(min, constants.boards.columns.settings.min); this.#max = commons.int.check(max, constants.boards.columns.settings.max); this.#statusIds = commons.string.checkBulk(statusIds, constants.boards.columns.settings.statusIds); } getName = () => this.#name; getOrder = () => this.#order; getMin = () => this.#min; getMax = () => this.#max; getStatusIds = () => this.#statusIds; toString = () => `Column[${this.#name} #${this.#order}]`; toJSON = () => { const json = { name: this.#name, order: this.#order }; if (this.#min) json.min = this.#min; if (this.#max) json.max = this.#max; if (commons.array.notEmpty(this.#statusIds)) json.statusIds = [...this.#statusIds]; return json; }; static check(column) { return commons.object.check(column, { name: 'column', className: 'BoardColumn', _class: BoardColumn }); } static checkBulk(columns) { if (commons.array.not(columns)) throw commons.errors.invalid.type.new('bulk of columns', 'array'); for (const column of columns) this.check(column); return columns; } static create({ name, order, min, max, statusIds } = {}) { try { return Promise.resolve(new BoardColumn({ name, order, min, max, statusIds })); } catch (error) { return Promise.reject(error); } } } module.exports = BoardColumn;