edupage-api-forweb
Version:
Simple node.js package to manage your EduPage account.
96 lines (76 loc) • 1.73 kB
JavaScript
const RawData = require("../lib/RawData");
const Edupage = require("./Edupage");
/**
* @typedef {import("../lib/RawData").RawDataObject} RawDataObject
*/
class Season extends RawData {
/**
* Creates an instance of Season.
* @param {RawDataObject} [data={}]
* @param {Edupage} [edupage=null]
* @memberof Season
*/
#edupage;
constructor(data = {}, edupage = null) {
super(data);
/**
* @type {Edupage}
*/
this.#edupage = edupage;
/**
* @type {string}
*/
this.id = data.id;
/**
* @type {Date}
*/
this.fromDate = null;
/**
* @type {Date}
*/
this.toDate = null;
/**
* @type {string}
*/
this.name = data.nazov;
/**
* @type {number}
*/
this.halfYear = +data.polrok;
/**
* @type {number}
*/
this.index = +data.poradie;
/**
* @type {Season}
*/
this.supSeason = null;
/**
* @type {string[]}
*/
this.types = data.typy;
/**
* @type {Season}
*/
this.classificationSeason = null;
/**
* @type {boolean}
*/
this.isClassification = !!data.klasifikacny;
if(this.#edupage) Season.prototype.init.call(this);
}
/**
*
* @param {Edupage} [edupage=null]
* @memberof Message
*/
init(edupage = null) {
if(edupage) this.#edupage = edupage;
const year = this.#edupage.year;
this.fromDate = new Date(this._data.od.replace("Y0", year).replace("Y1", year + 1));
this.toDate = new Date(this._data.do.replace("Y0", year).replace("Y1", year + 1));
this.supSeason = this.#edupage.seasons.find(e => e.id == this._data.nadobdobie) || null;
if(this.isClassification) this.classificationSeason = this.#edupage.seasons.find(e => e.id == this._data.klasifikacny) || null;
}
}
module.exports = Season;