UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

72 lines (61 loc) 2.85 kB
const commons = require('../../commons'); const constants = require('../constants'); class Sprint { #id; #state; #name; #startDate; #endDate; #completeDate; #createdDate; #originBoardId; #goal; constructor({ id, state, name, startDate, endDate, completeDate, createdDate, originBoardId, goal } = {}) { this.#id = commons.int.check(id, constants.sprints.settings.id); this.#state = commons.string.check(state, constants.sprints.settings.state); this.#name = commons.string.check(name, constants.sprints.settings.name); this.#startDate = commons.date.check(startDate, constants.sprints.settings.startDate); this.#endDate = commons.date.check(endDate, constants.sprints.settings.endDate); this.#completeDate = commons.date.check(completeDate, constants.sprints.settings.completeDate); this.#createdDate = commons.date.check(createdDate, constants.sprints.settings.createdDate); this.#originBoardId = commons.int.check(originBoardId, constants.sprints.settings.originBoardId); this.#goal = commons.string.check(goal, constants.sprints.settings.goal); } getId = () => this.#id; getState = () => this.#state; getName = () => this.#name; getStartDate = () => this.#startDate; getEndDate = () => this.#endDate; getCompleteDate = () => this.#completeDate; getCreatedDate = () => this.#createdDate; getOriginBoardId = () => this.#originBoardId; getGoal = () => this.#goal; compare = sprint => (sprint instanceof Sprint ? commons.date.compare(this.#startDate, sprint.getStartDate()) : 1); static check(sprint) { return commons.object.check(sprint, { name: 'sprint', className: 'Sprint', _class: Sprint }); } static resolve(sprint) { return commons.object.resolve(sprint, { name: 'sprint', className: 'Sprint', _class: Sprint }); } static create({ id, state, name, startDate, endDate, completeDate, createdDate, originBoardId, goal } = {}) { try { return Promise.resolve( new Sprint({ id, state, name, startDate, endDate, completeDate, createdDate, originBoardId, goal }) ); } catch (error) { return Promise.reject(error); } } toString = () => `Sprint[${this.#name} #${this.#id}]`; toJSON = () => { const json = { id: this.#id, name: this.#name, state: this.#state }; if (this.#startDate) json.startDate = this.#startDate.toISOString(); if (this.#createdDate) json.createdDate = this.#createdDate.toISOString(); if (this.#completeDate) json.completeDate = this.#completeDate.toISOString(); if (this.#endDate) json.endDate = this.#endDate.toISOString(); if (this.#goal) json.goal = this.#goal; if (this.#originBoardId) json.originBoardId = this.#originBoardId; return json; }; } module.exports = Sprint;