oa-jira
Version:
Octet Agile's JIRA connectivity project.
42 lines (36 loc) • 1.41 kB
JavaScript
const commons = require('../../commons');
const constants = require('../constants');
const Changes = require('./changes.class');
const IssueData = require('./issue.data.class');
class IssueSnapshot {
#snapshots;
#previous;
#time;
#data;
#changes;
#next;
constructor(snapshots, { previous, time, data, next, changes } = {}) {
this.#snapshots = snapshots;
this.#previous = commons.date.check(previous, constants.issue.snapshot.settings.previous);
this.#time = commons.date.check(time, constants.issue.snapshot.settings.time);
this.#data = IssueData.check(data);
this.#next = commons.date.check(next, constants.issue.snapshot.settings.next);
this.#changes = Changes.check(changes);
}
getPrevious = () => (this.#previous ? this.#snapshots.get(this.#previous.toISOString()) : null);
getTime = () => this.#time;
getData = () => this.#data;
getChanges = () => this.#changes;
getNext = () => (this.#next ? this.#snapshots.get(this.#next.toISOString()) : null);
toJSON = () => {
const json = {
time: this.getTime().toISOString(),
data: this.getData().toJSON(),
changes: this.getChanges().toJSON()
};
if (this.getPrevious()) json.previous = this.#previous.toISOString();
if (this.getNext()) json.next = this.#next.toISOString();
return json;
};
}
module.exports = IssueSnapshot;