UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

83 lines (69 loc) 2.78 kB
const commons = require('../../commons'); const constants = require('../constants'); const Project = require('../classes/project.class'); const Resolution = require('../classes/resolution.class'); const Sprint = require('../classes/sprint.class'); const Status = require('../classes/status.class'); const Type = require('../classes/type.class'); const Version = require('../classes/version.class'); class IssueData { #summary; #updated; #complexity; #sprint; #type; #resolution; #project; #status; #versions; constructor({ summary, updated, complexity, sprint, type, resolution, project, status, versions }) { this.#summary = commons.string.check(summary, constants.issue.data.settings.summary); this.#updated = commons.date.check(updated, constants.issue.data.settings.updated); this.#type = Type.check(type); this.#status = Status.check(status); this.#project = Project.check(project); this.#complexity = commons.int.check(complexity, constants.issue.data.settings.complexity); this.#sprint = sprint ? Sprint.check(sprint) : null; this.#resolution = resolution ? Resolution.check(resolution) : null; this.#versions = versions ? Version.checkBulk(versions) : []; } getSummary = () => this.#summary; getType = () => this.#type; getComplexity = () => this.#complexity; getSprint = () => this.#sprint; getResolution = () => this.#resolution; getProject = () => this.#project; getStatus = () => this.#status; getVersions = () => this.#versions; getUpdated = () => this.#updated; toString = () => `Data[${this.#summary} - ${this.#updated.toISOString()}]`; toJSON = () => { const json = { type: this.#type.toJSON(), summary: this.#summary, project: this.#project.toJSON(), status: this.#status.toJSON() }; if (this.#complexity) json.complexity = this.#complexity; if (this.#sprint) json.sprint = this.#sprint.toJSON(); if (this.#resolution) json.resolution = this.#resolution.toJSON(); if (this.#versions.length > 0) { json.versions = []; for (const version of this.#versions) json.versions.push(version.toJSON()); } return json; }; static check(issueData) { return commons.object.check(issueData, { name: 'issue data', className: 'IssueData', _class: IssueData }); } static create({ summary, complexity, updated, project, sprint, type, resolution, versions, status } = {}) { try { return Promise.resolve( new IssueData({ summary, complexity, updated, project, sprint, type, resolution, versions, status }) ); } catch (error) { return Promise.reject(error); } } } module.exports = IssueData;