diff --git a/README.md b/README.md index 78ef653..1e5ed18 100644 --- a/README.md +++ b/README.md @@ -505,7 +505,7 @@ class Edupage extends RawData { async refreshGrades(_update?: boolean = true): void; // Refreshes grades of currently logged user _updateInternalValues(): void; // Updates all fields of the current instance (called internally after - // any of the "refresh" methods, if `_update` is set to `true`) + // any of the "refresh" methods, if `_update` is set to `true`) async uploadAttachment(filepath: string): Promise; async api(options: APIOptions): Promise; @@ -699,6 +699,14 @@ class Period extends RawData { startTime: string; endTime: string; + + getInvalid(data?: { //Creates new invalid Period + id?: string?, + name?: string, + short?: string, + startTime?: string, + endTime?: string + } = null): Period; } ``` @@ -1041,46 +1049,46 @@ enum Gender { This enum contains records about the timeline item types. ```typescript enum TimelineItemType { - MESSAGE = "sprava", - MESSAGE_TO_SUBTITUTER = "spravasuplujucemu", - NOTICEBOARD = "nastenka", - GRADE_ANNOUNCEMENT = "nastenka", - GRADE = "znamka", - NOTE = "vcelicka", - HOMEWORK = "homework", - HOMEWORK_STUDENT_STATE = "homework", - ABSENCE_NOTE = "ospravedlnenka", - ABSENCE_NOTE_REMINDER = "ospravedlnenka_reminder", - PROCESS = "process", - PROCESS_ADMIN = "processadmin", - STUDENT_ABSENT = "student_absent", - ACCIDENT = "accident", - EVENT = "event", - TIMETABLE = "timetable", - SUBSTITUTION = "substitution", - CANTEEN_MENU = "stravamenu", - CANTEEN_CREDIT = "strava_kredit", - CANTEEN_SUSPEND_REINSTATE_ORDERS = "strava_prerusObnovObj", - CANTEEN_OPENING = "strava_vydaj", - SURVEY = "anketa", - PLAN = "plan", - SETTINGS = "settings", - ALBUM = "album", - NEWS = "news", - TEST_ASSIGNMENT = "testpridelenie", - TEST_RESULT = "testvysledok", - CHAT = "chat", - CHECK_IN = "pipnutie", - CONSULTATION_MESSAGE = "konzultaciemsg", - CONSULTATION = "konzultacie", - PAYMENTS = "payments", - SIGN_IN = "signin", - CURRICULUM = "ucivo", - CURRICULUM_REMINDER = "ucivo_reminder", - BLACKBOARD = "bb", - STUDENT_PICKUP = "odchadzka", - TIMETABLE_CLOUD_GENERATE = "ttcloudgen", - CONFIRMATION = "confirmation", - CONTEST = "contest" + MESSAGE = "sprava", + MESSAGE_TO_SUBTITUTER = "spravasuplujucemu", + NOTICEBOARD = "nastenka", + GRADE_ANNOUNCEMENT = "nastenka", + GRADE = "znamka", + NOTE = "vcelicka", + HOMEWORK = "homework", + HOMEWORK_STUDENT_STATE = "homework", + ABSENCE_NOTE = "ospravedlnenka", + ABSENCE_NOTE_REMINDER = "ospravedlnenka_reminder", + PROCESS = "process", + PROCESS_ADMIN = "processadmin", + STUDENT_ABSENT = "student_absent", + ACCIDENT = "accident", + EVENT = "event", + TIMETABLE = "timetable", + SUBSTITUTION = "substitution", + CANTEEN_MENU = "stravamenu", + CANTEEN_CREDIT = "strava_kredit", + CANTEEN_SUSPEND_REINSTATE_ORDERS = "strava_prerusObnovObj", + CANTEEN_OPENING = "strava_vydaj", + SURVEY = "anketa", + PLAN = "plan", + SETTINGS = "settings", + ALBUM = "album", + NEWS = "news", + TEST_ASSIGNMENT = "testpridelenie", + TEST_RESULT = "testvysledok", + CHAT = "chat", + CHECK_IN = "pipnutie", + CONSULTATION_MESSAGE = "konzultaciemsg", + CONSULTATION = "konzultacie", + PAYMENTS = "payments", + SIGN_IN = "signin", + CURRICULUM = "ucivo", + CURRICULUM_REMINDER = "ucivo_reminder", + BLACKBOARD = "bb", + STUDENT_PICKUP = "odchadzka", + TIMETABLE_CLOUD_GENERATE = "ttcloudgen", + CONFIRMATION = "confirmation", + CONTEST = "contest" } ``` diff --git a/package.json b/package.json index eab57bc..c08a075 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "edupage-api", - "version": "0.7.13", + "version": "0.7.14", "description": "Simple node.js package to manage your EduPage account.", "main": "index.js", "scripts": { diff --git a/src/Lesson.js b/src/Lesson.js index 9e6bb2c..8d910ca 100644 --- a/src/Lesson.js +++ b/src/Lesson.js @@ -128,15 +128,27 @@ class Lesson extends RawData { this.edupage.assignments.find(e => e.hwkid && e.hwkid.includes(id.split(":")[1] || id)) ); + //In case the period is not specified if(!this.period) { - return FatalError.warn(new ReferenceError("Failed to find period for lesson"), { - query: this._data.flags.dp0.period, + const periodId = this._data.flags.dp0.period; + + //There is a period id, but it's not in the periods list + if(periodId) return FatalError.warn(new ReferenceError("Failed to find period for lesson"), { + query: periodId, periods: this.edupage.periods, _data_lesson: this._data, _data_edupage: this.edupage._data.dbi?.periods }); - } else { - //Set the lesson start time + + //There is no period id specified, so use time at least + this.period = Period.getInvalid({ + startTime: this._data.flags.dp0.starttime, + endTime: this._data.flags.dp0.endtime, + }); + } + + //Set the lesson start time + if(this.period.startTime) { const d = this.period.startTime.split(":"); this.date.setHours(+d[0], +d[1]); } diff --git a/src/Period.js b/src/Period.js index eb3be1a..9d92e28 100644 --- a/src/Period.js +++ b/src/Period.js @@ -38,6 +38,32 @@ class Period extends RawData { */ this.endTime = data.endtime; } + + // eslint-disable-next-line valid-jsdoc + /** + * Creates new invalid Period + * @static + * @param {{id?: string?, name?: string, short?: string, startTime?: string, endTime?: string}} [data=null] Data to be used to create the Period (if there's any) + * @return {Period} Created Period + * @memberof Period + */ + static getInvalid(data = null) { + const { + id = null, + name = "Unknown Period", + short = "?", + startTime = "00:00", + endTime = "00:00" + } = data || {}; + + return new Period({ + id, + name, + short, + startTime, + endTime + }); + } } module.exports = Period; \ No newline at end of file