Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passage de la version 0.2.6 à 0.2.7 #15

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- **0.2.0**: Réécriture en **typescript**
- **1.0.0**: Quand le module sera stable

## 0.2.7
- Conversion des dates de la vie-scolaire renvoyé par ED (Merci Rémy)
- Fix de la réponse de l'EDT
- Ajout des erreurs A2F_ERROR et ACCOUNT_DISABLED en vue du nouveau système de QCM

## 0.2.6

- Ajout de la propriété `_accessToken` dans le fichier Session
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ keywords:
- ecoledirecte
- papillon
license: GPL-3.0
version: 0.2.6
date-released: '2024-03-15'
version: 0.2.7
date-released: '2024-03-30'
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Le module est exporté vers NPM, il doit donc respecter les règles de codage de
- [ ] Cloud
- [x] Lister les membres
- [ ] Cloud
- [ ] Téléchargement de fichiers (`/telechargement.awp`)
- [x] Téléchargement de fichiers (`/telechargement.awp`)
- [x] Commandes

## Documentation
Voir le fichier [`DOCUMENTATION.md`](DOCUMENTATION.md)
Expand Down
14 changes: 14 additions & 0 deletions examples/schoollife.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { login, ED } from "./login";

// Exemple de schoolLife

login().then(() => {
ED.schoolLife.fetch().then(response => {
for (const sanctionsEncouragement of response.sanctionsEncouragements) {
console.log(`[${sanctionsEncouragement.typeElement}] ${sanctionsEncouragement.libelle} le ${sanctionsEncouragement.date} par ${sanctionsEncouragement.par}; ${sanctionsEncouragement.motif} ${sanctionsEncouragement.commentaire}`)
}
for (const absencesRetard of response.absencesRetards) {
console.log(`[${absencesRetard.typeElement}] ${absencesRetard.libelle} le ${absencesRetard.date} par ${absencesRetard.par}; ${absencesRetard.motif} ${absencesRetard.commentaire}`)
}
});
});
5 changes: 4 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"preset": "ts-jest",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^~/(.*)$": "<rootDir>/src/$1"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@papillonapp/ed-core",
"version": "0.2.6",
"version": "0.2.7",
"description": "API EcoleDirecte pour PapillonApp (c)",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
7 changes: 6 additions & 1 deletion src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
UNAUTHORIZED,
WRONG_CREDENTIALS,
INVALID_API_URL,
OBJECT_NOT_FOUND, INVALID_BODY
OBJECT_NOT_FOUND,
INVALID_BODY,
A2F_ERROR
} from "~/errors";
import {RequestOptions} from "~/utils/types/requests";
import {response} from "~/types/v3/responses/default/responses";
Expand Down Expand Up @@ -70,6 +72,9 @@ class Request {
if (response.code == 210) {
throw OBJECT_NOT_FOUND.drop(response.message);
}
if(response.code == 250) {
throw A2F_ERROR.drop();
}
return response;
}) as Promise<response>;
}
Expand Down
6 changes: 5 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const MODULE_DISABLE = error(8, (moduleName: string) => `The module is not activ
const INVALID_API_URL = error(9, "The API URL provided is invalid.");
const OBJECT_NOT_FOUND = error(10, "The object you were trying to retrieve was not found by Ecoledirecte (you provided an `id`, and the request errored with code 210).");
const INVALID_BODY = error(11, "Values provided in body are wrong and the request errored with code 512.");
const A2F_ERROR = error(12, "Dual authentication required");
const ACCOUNT_DISABLED = error(13, "Disabled Account");

function error(code: number, message: ErrorMessage){
return {
Expand All @@ -35,5 +37,7 @@ export {
MODULE_DISABLE,
INVALID_API_URL,
OBJECT_NOT_FOUND,
INVALID_BODY
INVALID_BODY,
A2F_ERROR,
ACCOUNT_DISABLED,
};
14 changes: 10 additions & 4 deletions src/fetch/getSchoolLife.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import bodyToString from "~/utils/body";
import {Session} from "~/session";
import {schoolLifeRequestData} from "~/types/v3/requests/student";
import {schoolLifeRes, schoolLifeResData} from "~/types";
import {schoolLifeRes, EDCoreSchoolLifeResData} from "~/utils/types/schoollife";
import {dateStringAsTimeInterval} from "~/utils/dates";

class GetSchoolLife {

Expand All @@ -12,15 +13,20 @@ class GetSchoolLife {

}

async fetch(): Promise<schoolLifeResData> {
async fetch(): Promise<EDCoreSchoolLifeResData> {
const url = `/eleves/${this.session.student.id}/viescolaire.awp?verbe=get`;
const data = {} as schoolLifeRequestData;
return await this.session.request.post(url, bodyToString(data)).then((response: schoolLifeRes) => {
return response.data;
}) as Promise<schoolLifeResData>;
const res = response.data as EDCoreSchoolLifeResData;
for (let i = 0; i < res.absencesRetards.length; i++) {
Vilerio marked this conversation as resolved.
Show resolved Hide resolved
res.absencesRetards[i].interval = dateStringAsTimeInterval(res.absencesRetards[i].displayDate);
}
return res;
}) as EDCoreSchoolLifeResData;
}
}

export {
GetSchoolLife
};

8 changes: 2 additions & 6 deletions src/fetch/getTimetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class GetTimetable {
avecTrous: false
} as timetableRequestData;
return await this.session.request.post(url, bodyToString(data)).then((response: timetableRes) => {
return {
...response.data
};
return response.data;
}) as Promise<timetableCourseList>;
}

Expand All @@ -34,9 +32,7 @@ class GetTimetable {
avecTrous: false
} as timetableRequestData;
return await this.session.request.post(url, bodyToString(data)).then((response: timetableRes) => {
return {
...response.data
};
return response.data;
}) as Promise<timetableCourseList>;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/utils/base64.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* This function decodes the b64 input string, and decode uri escaped chars, if escape function exists
/**
* This function decodes the b64 input string, and decode uri escaped chars, if escape function exists.
*
* Escape function allow to transform encoded chars into utf-8 ones.
* */
export function decodeString(value: string) {
if (escape) {
Expand Down
84 changes: 84 additions & 0 deletions src/utils/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
export type Timeinterval = {
Vilerio marked this conversation as resolved.
Show resolved Hide resolved
start: string
end: string
};

export function dateAsISO860(str: string): string {
const parts = str.split(" ");
let month = "01";
switch (parts[2]) {
case "janvier":
month = "01";
break;
case "février":
month = "02";
break;
case "mars":
month = "03";
break;
case "avril":
month = "04";
break;
case "mai":
month = "05";
break;
case "juin":
month = "06";
break;
case "juillet":
month = "07";
break;
case "août":
month = "08";
break;
case "septembre":
month = "09";
break;
case "octobre":
month = "10";
break;
case "novembre":
month = "11";
break;
case "décembre":
month = "12";
break;
}
return parts[3] + "-" + month + "-" + parts[1] + "T" + parts[5] + ":00.000+02:00";
}

export function dateStringAsTimeInterval(str: string): Timeinterval | undefined {
if (str.includes("du")) {
/**
* @example
* str is equal to "du mercredi 21 février 2024 au jeudi 22 février 2024"
*/
const parts = str.split("au");
const start = dateAsISO860(parts[0].replace("du", "").trim());
const end = dateAsISO860(parts[1].trim());
return {start: start, end: end} as Timeinterval;
}
if (str.includes("le")) {
/**
* @example
* str is equal to "le mercredi 21 février 2024 de 08:55 à 09:45"
* or "le mercredi 21 février 2024"
*/
const parts = str.split("à");

let startDate, endDate;

// C'est une journée complète ("le mercredi 21 février 2024")
if (!str.includes(":")) {
startDate = parts[0].replace("le", "").trim() + " de 00:00";
endDate = parts[0].split("de")[0].replace("le", "").trim() + " de 23:59";
} else {
startDate = parts[0].replace("le", "").trim();
endDate = parts[0].split("de")[0].replace("le", "").trim() + " de " + parts[1].trim();
}
const start = dateAsISO860(startDate);
const end = dateAsISO860(endDate);
return { start: start, end: end } as Timeinterval;
}
return undefined;
}
13 changes: 13 additions & 0 deletions src/utils/types/schoollife.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {failureRes, schoolLifeItem, schoolLifeResData, schoolLifeResSuccess} from "~/types/v3";
import {Timeinterval} from "~/utils/dates";

export type schoolLifeRes = schoolLifeSuccess | failureRes;

export type schoolLifeSuccess = schoolLifeResSuccess & { data: EDCoreSchoolLifeResData };

export type EDCoreSchoolLifeItem = schoolLifeItem & { interval?: Timeinterval };

export type EDCoreSchoolLifeResData = schoolLifeResData & {
sanctionsEncouragements: Array<EDCoreSchoolLifeItem>;
absencesRetards: Array<EDCoreSchoolLifeItem>;
};
Loading