UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

55 lines (47 loc) 2.21 kB
const commons = require('../../commons'); const constants = require('../constants'); const IssueSnapshots = require('./issue.snapshots.class'); class Issue { #key; #created; #resolutiondate; #snapshots; constructor({ key, created, resolutiondate, snapshots } = {}) { this.#key = commons.string.check(key, constants.issue.settings.key); this.#created = commons.date.check(created, constants.issue.settings.created); this.#resolutiondate = commons.date.check(resolutiondate, constants.issue.settings.resolutiondate); this.#snapshots = IssueSnapshots.check(snapshots); } getKey = () => this.#key; getCreated = () => this.#created; getResolutionDate = () => this.#resolutiondate; getSummary = () => this.#snapshots.getLast().getData().getSummary(); getType = () => this.#snapshots.getLast().getData().getType(); getComplexity = () => this.#snapshots.getLast().getData().getComplexity(); getSprint = () => this.#snapshots.getLast().getData().getSprint(); getSprints = () => this.#snapshots.getSprints(); getResolution = () => this.#snapshots.getLast().getData().getResolution(); getProject = () => this.#snapshots.getLast().getData().getProject(); getStatus = () => this.#snapshots.getLast().getData().getStatus(); getVersions = () => this.#snapshots.getLast().getData().getVersions(); getUpdated = () => this.#snapshots.getLast().getData().getUpdated(); getSnapshots = () => this.#snapshots; getLast = () => this.#snapshots.getLast(); getFirst = () => this.#snapshots.getFirst(); static resolve(issue) { return commons.object.resolve(issue, { name: 'issue', className: 'Issue', _class: Issue }); } static create({ key, created, resolutiondate, snapshots } = {}) { try { return Promise.resolve(new Issue({ key, created, resolutiondate, snapshots })); } catch (error) { return Promise.reject(error); } } toJSON = () => { const json = { key: this.#key, created: this.#created, snapshots: this.#snapshots.toJSON() }; if (this.#resolutiondate) json.resolutiondate = this.#resolutiondate.toISOString(); return json; }; } module.exports = Issue;