mirror of
https://github.com/dd060606/WebAurion-API.git
synced 2026-01-18 16:47:26 +01:00
schedule api fix
This commit is contained in:
@@ -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)
|
||||
public fetchSchedule(
|
||||
startDate?: string,
|
||||
endDate?: string,
|
||||
): Promise<ScheduleEvent[]> {
|
||||
public fetchSchedule(startDate?: string): Promise<ScheduleEvent[]> {
|
||||
return new Promise<ScheduleEvent[]>(async (resolve, reject) => {
|
||||
try {
|
||||
const schedulePage = await this.session.sendGET<string>(
|
||||
@@ -40,8 +37,10 @@ class ScheduleApi {
|
||||
"j_idt118",
|
||||
viewState,
|
||||
);
|
||||
if (startDate && endDate) {
|
||||
if (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);
|
||||
} else {
|
||||
// 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);
|
||||
const startTimestamp = currentDate.getTime();
|
||||
// On fixe la date de fin à une semaine après
|
||||
const endTimestamp =
|
||||
startTimestamp + 6 * 24 * 60 * 60 * 1000;
|
||||
params.append(
|
||||
|
||||
@@ -23,6 +23,7 @@ export function getJSONSchedule(xml: string): object {
|
||||
return JSON.parse(json)["events"];
|
||||
}
|
||||
|
||||
// On convertit la réponse du serveur XML en cours du planning
|
||||
export function scheduleResponseToEvents(response: string): ScheduleEvent[] {
|
||||
const json: any = getJSONSchedule(response);
|
||||
|
||||
@@ -31,11 +32,11 @@ export function scheduleResponseToEvents(response: string): ScheduleEvent[] {
|
||||
const eventInfo = event.title.split(" - ");
|
||||
|
||||
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 title = "";
|
||||
if (eventInfo.length >= 9) {
|
||||
subject = eventInfo[eventInfo.length - 5].trim();
|
||||
subject = eventInfo[eventInfo.length - 6].trim();
|
||||
title = eventInfo[eventInfo.length - 4].trim();
|
||||
} else {
|
||||
subject = eventInfo[eventInfo.length - 4].trim();
|
||||
@@ -54,8 +55,6 @@ export function scheduleResponseToEvents(response: string): ScheduleEvent[] {
|
||||
learners,
|
||||
start: event.start,
|
||||
end: event.end,
|
||||
allDay: event.allDay,
|
||||
editable: event.editable,
|
||||
className: event.className,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -7,7 +7,5 @@ type ScheduleEvent = {
|
||||
learners: string;
|
||||
start: string;
|
||||
end: string;
|
||||
allDay: boolean;
|
||||
editable: boolean;
|
||||
className: string;
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ describe("ScheduleApi", () => {
|
||||
|
||||
const session = await login(username, password);
|
||||
const schedule = await session.getScheduleApi().fetchSchedule();
|
||||
console.log(schedule);
|
||||
expect(schedule).not.toBeNull();
|
||||
expect(schedule).toBeInstanceOf(Array);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user