Skip to content

Commit

Permalink
feat: implement holidays on instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Feb 23, 2024
1 parent 04e45ba commit 7d255d7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
17 changes: 17 additions & 0 deletions examples/holidays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { authenticatePronoteCredentials, PronoteApiAccountId } from "../src";

(async () => {
const pronote = await authenticatePronoteCredentials("https://pronote-vm.dev/pronote", {
accountTypeID: PronoteApiAccountId.Student,
username: "lisa.boulanger", // using my VM credentials here because the demo instance doesn't have any messages.
password: "12345678",

// Because this is just an example, don't forget to change this.
deviceUUID: "my-device-uuid"
});

for (const holiday of pronote.holidays) {
console.info("=>", holiday.name);
console.info("Starts", holiday.start.toLocaleDateString(), "until", holiday.end.toLocaleDateString());
}
})();
7 changes: 6 additions & 1 deletion src/client/Pronote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { PronoteApiAttendanceItemType } from "~/constants/attendance";
import { StudentAbsence, StudentDelay, StudentPunishment } from "~/parser/attendance";
import { callApiUserMessageRecipients } from "~/api/user/messageRecipients";
import { FetchedMessageRecipient } from "~/parser/recipient";
import { Holiday } from "..";

export default class Pronote {
/**
Expand Down Expand Up @@ -117,12 +118,14 @@ export default class Pronote {

/** An absolute URL giving the profile picture of the logged in student, if exists. */
public studentProfilePictureURL?: string;
public periods: Array<Period>;
public periods: Period[];
private periodsByOnglet: Map<PronoteApiOnglets, OngletPeriods>;

public isDelegate: boolean;
public isMemberCA: boolean;

public holidays: Holiday[];

private queue: Queue;

constructor (
Expand Down Expand Up @@ -173,6 +176,8 @@ export default class Pronote {
// TODO: user.ressource.nbMaxJoursDeclarationAbsence;
// TODO: user.ressource.listeGroupes

this.holidays = loginInformations.donnees.General.listeJoursFeries.V.map((holiday) => new Holiday(holiday));

// For further requests, we implement a queue.
this.queue = new Queue();
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export { PronoteApiUserMessageRecipientType } from "~/constants/recipients";

// Exporting main classes.
export { default as Pronote } from "~/client/Pronote";
export { default as Holiday } from "~/parser/holiday";
export { StudentSubject } from "~/parser/subject";
export { StudentAttachment } from "~/parser/attachment";
export { StudentHomework } from "~/parser/homework";
Expand Down
36 changes: 36 additions & 0 deletions src/parser/holiday.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PronoteApiLoginInformations } from "~/api";
import { readPronoteApiDate } from "~/pronote/dates";

class Holiday {
readonly #id: string;
readonly #name: string;

readonly #start: Date;
readonly #end: Date;

constructor (data: PronoteApiLoginInformations["response"]["donnees"]["General"]["listeJoursFeries"]["V"][number]) {
this.#id = data.N;
this.#name = data.L;

this.#start = readPronoteApiDate(data.dateDebut.V);
this.#end = readPronoteApiDate(data.dateFin.V);
}

public get id (): string {
return this.#id;
}

public get name (): string {
return this.#name;
}

public get start (): Date {
return this.#start;
}

public get end (): Date {
return this.#end;
}
}

export default Holiday;

0 comments on commit 7d255d7

Please sign in to comment.