Skip to content

Commit

Permalink
Fixed missing period id in daily plan (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
loumadev committed Dec 13, 2021
1 parent aca20bd commit 9e06841
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 47 deletions.
92 changes: 50 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attachment>;
async api(options: APIOptions): Promise<RawDataObject | string>;
Expand Down Expand Up @@ -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;
}
```

Expand Down Expand Up @@ -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"
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
20 changes: 16 additions & 4 deletions src/Lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
26 changes: 26 additions & 0 deletions src/Period.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 9e06841

Please sign in to comment.