Skip to content

Commit

Permalink
[Fix] New rules linter
Browse files Browse the repository at this point in the history
  • Loading branch information
camarm-dev committed Feb 17, 2024
1 parent e8fe5db commit a387efc
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 153 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Session } from "~/session"
import { Session } from "~/session";

export {
Session as EDCore
}
};
30 changes: 15 additions & 15 deletions src/Request.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { API } from "./constants"
import { API } from "./constants";
import {Session} from "./session";
import {SESSION_EXPIRED, TOKEN_INVALID, UNAUTHORIZED, WRONG_CREDENTIALS} from "~/errors";
import {RequestOptions} from "~/utils/types/requests";

class Request {

session: Session
ua: string
requestOptions: RequestOptions
session: Session;
ua: string;
requestOptions: RequestOptions;

constructor(session: Session) {
this.session = session;
this.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
this.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36";
this.requestOptions = {
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded"
}
}
};
}

get() {

}

post(url: string, body: string) {
if(this.session.isLoggedIn) this.requestOptions.headers["X-token"] = this.session._token
const finalUrl = API + url
if(this.session.isLoggedIn) this.requestOptions.headers["X-token"] = this.session._token;
const finalUrl = API + url;
return fetch(finalUrl, {
method: "POST",
headers: this.requestOptions.headers,
Expand All @@ -35,22 +35,22 @@ class Request {
.then(res => {
const response = res.startsWith("{") ? JSON.parse(res) : res;
if (response.code == 525) {
throw SESSION_EXPIRED.drop()
throw SESSION_EXPIRED.drop();
}
if (response.code == 520) {
throw TOKEN_INVALID.drop()
throw TOKEN_INVALID.drop();
}
if (response.code == 505) {
throw WRONG_CREDENTIALS.drop()
throw WRONG_CREDENTIALS.drop();
}
if (response.code == 403) {
throw UNAUTHORIZED.drop(response.message)
throw UNAUTHORIZED.drop(response.message);
}
return response
})
return response;
});
}
}

export {
Request
}
};
26 changes: 13 additions & 13 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import {account, loginRes, loginResSuccess} from "~/types/v3";
import bodyToString from "./utils/body"
import bodyToString from "./utils/body";
import {Session} from "./session";
import {AuthRequestBody} from "~/utils/types/auth";
import {EstablishmentInfo} from "~/utils/types/establishments";
import {AccountInfo, Profile} from "~/utils/types/accounts";

class Auth {

session: Session
session: Session;

constructor(session: Session) {
this.session = session;
}

async login(username: string, password: string) {
const url = "/login.awp?v=4.37.1"
const url = "/login.awp?v=4.37.1";
const body = {
identifiant: username,
motdepasse: encodeURIComponent(password),
isRelogin: false,
uuid: ""
} as AuthRequestBody
} as AuthRequestBody;
return await this.session.request.post(url, bodyToString(body)).then((response: loginRes) => {
if (response.code === 200) {
const res = response.data as loginResSuccess
const data = res.data
const res = response.data as loginResSuccess;
const data = res.data;

this.session._token = response.token;
const accounts = data.accounts[0]
const accounts = data.accounts[0];

this.session.modules = accounts.modules;
this.session.settings = accounts.parametresIndividuels;
Expand All @@ -38,7 +38,7 @@ class Auth {
return null;
}

})
});
}

setToken(token: string, id: number) {
Expand All @@ -49,17 +49,17 @@ class Auth {
}

getEtabInfo(data: account): EstablishmentInfo {
const profile= data.profile as Profile
const profile= data.profile as Profile;
return {
name: profile.nomEtablissement ?? "Établissement non spécifié",
id: profile.idEtablissement ?? "",
rne: profile.rneEtablissement ?? "",
logo: data.logoEtablissement,
}
};
}

getStudentInfo(data: account): AccountInfo {
const profile = data.profile as Profile
const profile = data.profile as Profile;
return {
id: data.id,
uid: data.uid,
Expand All @@ -74,10 +74,10 @@ class Auth {
sexe: profile.sexe ?? "",
classe: profile.classe,
photo: profile.photo ?? ""
}
};
}
}

export {
Auth
}
};
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const API = "https://api.ecoledirecte.com/v3"
export const API = "https://api.ecoledirecte.com/v3";

export default {
API
}
};
4 changes: 2 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function error(code: number, message: ErrorMessage){
code,
message: message instanceof Function && arg ? message(arg as string & DetailedMessage): message
})
}
};
}

export {
Expand All @@ -30,4 +30,4 @@ export {
CLOSED,
TOKEN_INVALID,
MODULE_DISABLE
}
};
16 changes: 8 additions & 8 deletions src/fetch/getCantine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ import {Session} from "~/session";

class GetCantine {

session: Session
session: Session;

constructor(session: Session) {
this.session = session;

}

getBarcode() {
const module = this.session.findModule("CANTINE_BARCODE")
const module = this.session.findModule("CANTINE_BARCODE");
if(module.enable) {
return module.params.numeroBadge
return module.params.numeroBadge;
} else {
return null
return null;
}
}

getReservations() {
const module = this.session.findModule("RESERVATIONS")
const module = this.session.findModule("RESERVATIONS");
if(module.enable) {
return module.params
return module.params;
} else {
return null
return null;
}
}

}

export {
GetCantine
}
};
12 changes: 6 additions & 6 deletions src/fetch/getDigitalManuals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {MODULE_DISABLE} from "~/errors"
import {MODULE_DISABLE} from "~/errors";
import {Session} from "~/session";
import bodyToString from "~/utils/body";

class GetDigitalManuals {

session: Session
session: Session;

constructor(session: Session) {
this.session = session;
Expand All @@ -13,13 +13,13 @@ class GetDigitalManuals {

fetch() {
if(!this.session.findModule("MANUELS_SCOLAIRES").enable) throw MODULE_DISABLE.drop("MANUELS_SCOLAIRES");
const url = `/Eleves/${this.session.student.id}/manuelsNumeriques.awp?verbe=get`
const data = {}
return this.session.request.post(url, bodyToString(data))
const url = `/Eleves/${this.session.student.id}/manuelsNumeriques.awp?verbe=get`;
const data = {};
return this.session.request.post(url, bodyToString(data));
}

}

export {
GetDigitalManuals
}
};
14 changes: 7 additions & 7 deletions src/fetch/getGrades.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import {Session} from "~/session";
import bodyToString from "../utils/body";
import {gradesRes} from "~/types/v3";
import {GradesRequestBody} from "~/utils/types/grades"
import {GradesRequestBody} from "~/utils/types/grades";

class GetGrades {

session: Session
session: Session;

constructor(session: Session) {
this.session = session;
}

fetch() {
const url = `/eleves/${this.session.student.id}/notes.awp?verbe=get`
const url = `/eleves/${this.session.student.id}/notes.awp?verbe=get`;
const body = {
anneeScolaire: ""
} as GradesRequestBody
} as GradesRequestBody;
return this.session.request.post(url, bodyToString(body)).then((response: gradesRes) => {
return response.data
})
return response.data;
});
}
}

export {
GetGrades
}
};
38 changes: 19 additions & 19 deletions src/fetch/getHomeworks.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import {Session} from "~/session";
import bodyToString from "~/utils/body";
import {textbookDateAssignement, textbookDateRes, textbookDateResData, textbookRes} from "~/types/v3"
import {textbookDateAssignement, textbookDateRes, textbookDateResData, textbookRes} from "~/types/v3";

class GetHomeworks {

session: Session
session: Session;

constructor(session: Session) {
this.session = session
this.session = session;
}

fetch() {
const url = `/Eleves/${this.session.student.id}/cahierdetexte.awp?verbe=get`
const data = {}
return this.session.request.post(url, bodyToString(data)).then(response => response as textbookRes)
const url = `/Eleves/${this.session.student.id}/cahierdetexte.awp?verbe=get`;
const data = {};
return this.session.request.post(url, bodyToString(data)).then(response => response as textbookRes);
}

getByDay(day: string) {
const url = `/Eleves/${this.session.student.id}/cahierdetexte/${day}.awp?verbe=get`
const data = {}
const url = `/Eleves/${this.session.student.id}/cahierdetexte/${day}.awp?verbe=get`;
const data = {};
return this.session.request.post(url, bodyToString(data)).then((response: textbookDateRes) => {

if (response.code == 200) {
const homeworks = response.data as textbookDateResData
const homeworks = response.data as textbookDateResData;

homeworks.matieres.forEach((homework: textbookDateAssignement, index: number) => {
const aFaire= homework.aFaire
if (!aFaire) return
const htmlContent = aFaire.contenu
const aFaire= homework.aFaire;
if (!aFaire) return;
const htmlContent = aFaire.contenu;
const span = document.createElement("span");
span.innerHTML = htmlContent;
// TODO: `contenuTexte` ou `contenu`
aFaire.contenu = [span.textContent || span.innerText].toString().replace(/ +/g," ");
homeworks.matieres[index].aFaire = aFaire
homeworks.matieres[index].aFaire = aFaire;
});

return homeworks;
} else {
return {
date: "",
matieres: []
} as textbookDateResData
} as textbookDateResData;
}
})
});
}

setStatus(homeworkID: number, isDone: boolean) {
const url = `/E/${this.session.student.id}/cahierdetexte.awp?verbe=put`
const url = `/E/${this.session.student.id}/cahierdetexte.awp?verbe=put`;
const data = {
"idDevoirsEffectues": [isDone ? homeworkID : null],
"idDevoirsNonEffectues": [isDone ? null : homeworkID]
}
return this.session.request.post(url, bodyToString(data))
};
return this.session.request.post(url, bodyToString(data));
}
}

export {
GetHomeworks
}
};
Loading

0 comments on commit a387efc

Please sign in to comment.