UNPKG

ecoledirecte.js

Version:

Good-looking client for EcoleDirecte's private API.

72 lines (71 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Grade = void 0; class Grade { constructor(o) { this.name = o.devoir; this.value = betterValue(o); this.classMax = !(isNaN(+o.maxClasse) || !o.maxClasse) ? +o.maxClasse : o.maxClasse || undefined; this.classAvg = !(isNaN(+o.moyenneClasse) || !o.moyenneClasse) ? +o.moyenneClasse : o.moyenneClasse || undefined; this.classMin = !(isNaN(+o.minClasse) || !o.minClasse) ? +o.minClasse : o.minClasse || undefined; this.outOf = +o.noteSur.replace(/,/, "."); this.weight = +o.coef; this.unweighted = o.nonSignificatif; this.isLetter = o.enLettre; this.date = new Date(o.date); this.dateTyped = new Date(o.dateSaisie); this.periodCode = o.codePeriode; this.subjectCode = o.codeMatiere; this.subjectName = o.libelleMatiere; this.subSubjectCode = o.codeSousMatiere || undefined; this.elements = o.elementsProgramme.map(e => ({ id: e.idElemProg, competenceId: e.idCompetence, name: e.libelleCompetence, description: e.descriptif, value: e.valeur, })); this.qcm = o.qcm ? { id: o.qcm.idQCM, name: o.qcm.titre, startsAt: new Date(o.qcm.debute), } : undefined; this._raw = o; } toJSON() { return { name: this.name, value: this.value, classMax: this.classMax, classAvg: this.classAvg, classMin: this.classMin, outOf: this.outOf, weight: this.weight, unweighted: this.unweighted, isLetter: this.isLetter, date: this.date, dateTyped: this.dateTyped, periodCode: this.periodCode, subjectCode: this.subjectCode, subjectName: this.subjectName, subSubjectCode: this.subSubjectCode, elements: this.elements, qcm: this.qcm, _raw: this._raw, }; } } exports.Grade = Grade; function betterValue(note) { if (note.enLettre) return note.valeur; return +note.valeur.replace(/,/, "."); }