UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

53 lines (42 loc) 1.59 kB
const commons = require('../../commons'); const constants = require('../constants'); const BoardColumn = require('./board.column.class'); class Board { #id; #name; #projectId; #columns; constructor({ id, name, projectId, columns } = {}) { this.#id = commons.int.check(id, constants.boards.settings.id); this.#name = commons.string.check(name, constants.boards.settings.name); this.#projectId = commons.string.check(projectId, constants.boards.settings.projectId); this.#columns = columns ? BoardColumn.checkBulk(columns) : []; } getId = () => this.#id; getName = () => this.#name; getProjectId = () => this.#projectId; getColumns = () => this.#columns; toString = () => `Board[${this.#name} #${this.#id}]`; toJSON = () => { const json = { id: this.#id, name: this.#name, projectId: this.#projectId }; if (commons.array.notEmpty(this.#columns)) { json.columns = {}; for (const column of this.#columns) json.columns[column.getOrder()] = column.toJSON(); } return json; }; static check(column) { return commons.object.check(column, { name: 'board', className: 'Board', _class: Board }); } static resolve(column) { return commons.object.resolve(column, { name: 'board', className: 'Board', _class: Board }); } static create({ id, name, projectId, columns } = {}) { try { return Promise.resolve(new Board({ id, name, projectId, columns })); } catch (error) { return Promise.reject(error); } } } module.exports = Board;