schedule api fix

This commit is contained in:
dd060606
2024-11-18 11:23:50 +01:00
parent 9e5725d14d
commit 39f9529177
4 changed files with 9 additions and 13 deletions

View File

@@ -12,10 +12,7 @@ class ScheduleApi {
} }
// Récupération de l'emploi du temps en fonction de la date de début et de fin (timestamps en millisecondes) // Récupération de l'emploi du temps en fonction de la date de début et de fin (timestamps en millisecondes)
public fetchSchedule( public fetchSchedule(startDate?: string): Promise<ScheduleEvent[]> {
startDate?: string,
endDate?: string,
): Promise<ScheduleEvent[]> {
return new Promise<ScheduleEvent[]>(async (resolve, reject) => { return new Promise<ScheduleEvent[]>(async (resolve, reject) => {
try { try {
const schedulePage = await this.session.sendGET<string>( const schedulePage = await this.session.sendGET<string>(
@@ -40,8 +37,10 @@ class ScheduleApi {
"j_idt118", "j_idt118",
viewState, viewState,
); );
if (startDate && endDate) { if (startDate) {
params.append("form:j_idt118_start", startDate); params.append("form:j_idt118_start", startDate);
// La date de fin est fixée à une semaine après la date de début
const endDate = startDate + 6 * 24 * 60 * 60 * 1000;
params.append("form:j_idt118_end", endDate); params.append("form:j_idt118_end", endDate);
} else { } else {
// On récupère le timestamp du lundi de la semaine en cours // On récupère le timestamp du lundi de la semaine en cours
@@ -54,6 +53,7 @@ class ScheduleApi {
); );
currentDate.setHours(0, 0, 0, 0); currentDate.setHours(0, 0, 0, 0);
const startTimestamp = currentDate.getTime(); const startTimestamp = currentDate.getTime();
// On fixe la date de fin à une semaine après
const endTimestamp = const endTimestamp =
startTimestamp + 6 * 24 * 60 * 60 * 1000; startTimestamp + 6 * 24 * 60 * 60 * 1000;
params.append( params.append(

View File

@@ -23,6 +23,7 @@ export function getJSONSchedule(xml: string): object {
return JSON.parse(json)["events"]; return JSON.parse(json)["events"];
} }
// On convertit la réponse du serveur XML en cours du planning
export function scheduleResponseToEvents(response: string): ScheduleEvent[] { export function scheduleResponseToEvents(response: string): ScheduleEvent[] {
const json: any = getJSONSchedule(response); const json: any = getJSONSchedule(response);
@@ -31,11 +32,11 @@ export function scheduleResponseToEvents(response: string): ScheduleEvent[] {
const eventInfo = event.title.split(" - "); const eventInfo = event.title.split(" - ");
let room = eventInfo[1].trim(); let room = eventInfo[1].trim();
// Pour les matières qui ne sont pas bien formatées... // Pour les matières qui ne sont pas bien formatées par défaut...
let subject = ""; let subject = "";
let title = ""; let title = "";
if (eventInfo.length >= 9) { if (eventInfo.length >= 9) {
subject = eventInfo[eventInfo.length - 5].trim(); subject = eventInfo[eventInfo.length - 6].trim();
title = eventInfo[eventInfo.length - 4].trim(); title = eventInfo[eventInfo.length - 4].trim();
} else { } else {
subject = eventInfo[eventInfo.length - 4].trim(); subject = eventInfo[eventInfo.length - 4].trim();
@@ -54,8 +55,6 @@ export function scheduleResponseToEvents(response: string): ScheduleEvent[] {
learners, learners,
start: event.start, start: event.start,
end: event.end, end: event.end,
allDay: event.allDay,
editable: event.editable,
className: event.className, className: event.className,
}; };
}); });

View File

@@ -7,7 +7,5 @@ type ScheduleEvent = {
learners: string; learners: string;
start: string; start: string;
end: string; end: string;
allDay: boolean;
editable: boolean;
className: string; className: string;
}; };

View File

@@ -11,7 +11,6 @@ describe("ScheduleApi", () => {
const session = await login(username, password); const session = await login(username, password);
const schedule = await session.getScheduleApi().fetchSchedule(); const schedule = await session.getScheduleApi().fetchSchedule();
console.log(schedule); expect(schedule).toBeInstanceOf(Array);
expect(schedule).not.toBeNull();
}); });
}); });