Skip to content

Commit

Permalink
fix(grades/attachments): add internal genre to URL builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Feb 22, 2024
1 parent 31c05b9 commit 390d8c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
10 changes: 6 additions & 4 deletions examples/grades-overview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { authenticatePronoteCredentials, PronoteApiAccountId, PronoteApiGradeType } from "../src";

(async () => {
const pronote = await authenticatePronoteCredentials("https://demo.index-education.net/pronote", {
const pronote = await authenticatePronoteCredentials("https://pronote-vm.dev/pronote", {
accountTypeID: PronoteApiAccountId.Eleve,
username: "demonstration",
password: "pronotevs",
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"
Expand Down Expand Up @@ -45,7 +45,7 @@ import { authenticatePronoteCredentials, PronoteApiAccountId, PronoteApiGradeTyp

gradesOverview.grades.forEach((grade) => {
console.log(grade.subject.name, ":", grade.comment || "(no description)");
console.log("Registered the", grade.date.toLocaleString(), "//", grade.period.name);
console.log("Registered the", grade.date.toLocaleString(), "//", period.name);

// If there
if (typeof grade.outOf === "number") {
Expand All @@ -60,6 +60,8 @@ import { authenticatePronoteCredentials, PronoteApiAccountId, PronoteApiGradeTyp
console.log("Average:", handleGradeValue(grade.average, grade.outOf, grade.coefficient));
console.log("Minimum:", handleGradeValue(grade.min, grade.outOf, grade.coefficient));
console.log("Maximum:", handleGradeValue(grade.max, grade.outOf, grade.coefficient));
if (grade.subjectFile) console.log("Subject:", grade.subjectFile.name, "=>", grade.subjectFile.url);
if (grade.correctionFile) console.log("Correction:", grade.correctionFile.name, "=>", grade.correctionFile.url);
}
else {
console.log("Grade doesn't have a valid 'outOf', shouldn't be counted.");
Expand Down
10 changes: 10 additions & 0 deletions src/constants/grades.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Required when building an URL to download a file
* attached to a grade.
*
* @remark Shouldn't be exported as it's only used internally.
*/
export enum PronoteApiGradeAttachmentType {
CorrectionFile = "DevoirCorrige",
SubjectFile = "DevoirSujet"
}
7 changes: 5 additions & 2 deletions src/parser/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class StudentAttachment {

constructor (
client: Pronote,
attachment: PronoteApiAttachment
attachment: PronoteApiAttachment,
additionalParameters = {}
) {
this.name = attachment.L ?? "";
this.type = attachment.G;
Expand All @@ -25,7 +26,9 @@ export class StudentAttachment {
// Some magical stuff Pronote requires.
const data = JSON.stringify({
N: this.id,
Actif: true
Actif: true,
// In some cases classes, this is required.
...additionalParameters
});

// Encrypt that magical stuff to add it in the URL.
Expand Down
9 changes: 7 additions & 2 deletions src/parser/grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type Pronote from "~/client/Pronote";
import { StudentSubject } from "~/parser/subject";
import { type PronoteApiGradeType, readPronoteApiGrade } from "~/pronote/grades";
import { readPronoteApiDate } from "~/pronote/dates";
import { StudentAttachment } from "./attachment";
import { PronoteApiAttachmentType } from "..";
import { StudentAttachment } from "~/parser//attachment";
import { PronoteApiAttachmentType } from "~/constants/attachments";
import { PronoteApiGradeAttachmentType } from "~/constants/grades";

export class StudentGrade {
readonly #id: string;
Expand Down Expand Up @@ -46,6 +47,8 @@ export class StudentGrade {
G: PronoteApiAttachmentType.File,
L: grade.libelleCorrige,
N: this.#id
}, { // Additional genre.
G: PronoteApiGradeAttachmentType.CorrectionFile
});
}

Expand All @@ -54,6 +57,8 @@ export class StudentGrade {
G: PronoteApiAttachmentType.File,
L: grade.libelleSujet,
N: this.#id
}, { // Additional genre.
G: PronoteApiGradeAttachmentType.SubjectFile
});
}
}
Expand Down

0 comments on commit 390d8c9

Please sign in to comment.