summaryrefslogtreecommitdiff
path: root/includes/external/school/node_modules/pronote-api/src/fetch/timetable.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
committerMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
commit3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch)
tree75be5fba4368472fb11c8015aee026b2b9a71888 /includes/external/school/node_modules/pronote-api/src/fetch/timetable.js
parent8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff)
downloadpluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'includes/external/school/node_modules/pronote-api/src/fetch/timetable.js')
-rw-r--r--includes/external/school/node_modules/pronote-api/src/fetch/timetable.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/includes/external/school/node_modules/pronote-api/src/fetch/timetable.js b/includes/external/school/node_modules/pronote-api/src/fetch/timetable.js
new file mode 100644
index 0000000..059b849
--- /dev/null
+++ b/includes/external/school/node_modules/pronote-api/src/fetch/timetable.js
@@ -0,0 +1,95 @@
+const { toPronoteWeek } = require('../data/dates');
+const { withId, checkDuplicates } = require('../data/id');
+
+const { getFilledDaysAndWeeks, getTimetable } = require('./pronote/timetable');
+
+async function timetable(session, user, from = new Date(), to = null)
+{
+ if (!to || to < from) {
+ to = new Date(from.getTime());
+ to.setDate(to.getDate() + 1);
+ }
+
+ const filled = await getFilledDaysAndWeeks(session, user);
+ if (!filled) {
+ return null;
+ }
+
+ const fromWeek = toPronoteWeek(session, from);
+ const toWeek = toPronoteWeek(session, to);
+
+ const weeks = [];
+ for (let i = fromWeek; i <= toWeek; i++) {
+ weeks.push(i);
+ }
+
+ const result = [];
+ for (const week of weeks) {
+ const timetable = await getTimetable(session, user, week);
+ const lessons = getTimetableWeek(session, timetable);
+
+ if (lessons) {
+ lessons.filter(l => l.from >= from && l.from <= to).forEach(lesson => {
+ if (!filled.filledWeeks.includes(week)) {
+ lesson.isCancelled = true;
+ }
+
+ result.push(lesson);
+ });
+ }
+ }
+
+ return result.sort((a, b) => a.from - b.from);
+}
+
+function getTimetableWeek(session, table) {
+ const result = [];
+ if (!table || !table.lessons) {
+ return
+ }
+
+ for (const lesson of table.lessons) {
+ const from = lesson.date;
+ const to = new Date(from.getTime() + (lesson.duration / session.params.ticksPerHour * 3600000));
+
+ const res = {
+ from,
+ to,
+ isDetention: lesson.isDetention,
+ remoteLesson: lesson.remoteLesson,
+ status: lesson.status,
+ hasDuplicate: !!table.lessons.find(l => l.date.getTime() === from.getTime() && l !== lesson)
+ };
+
+ let room, subject, teacher;
+ if (lesson.isDetention) {
+ subject = lesson.content[0];
+ teacher = lesson.content[1];
+ room = lesson.content[2];
+ } else {
+ if (lesson.content) {
+ subject = lesson.content.find(o => o.type === 16);
+ teacher = lesson.content.find(o => o.type === 3);
+ room = lesson.content.find(o => o.type === 17);
+ } else {
+ subject = 'Non défini';
+ room = 'Non défini';
+ teacher = 'Non défini';
+ }
+
+ res.isAway = (lesson.status || false) && !!lesson.status.match(/(.+)?prof(.+)?absent(.+)?/giu);
+ res.isCancelled = !res.isAway && lesson.isCancelled;
+ res.color = lesson.color;
+ }
+
+ res.subject = subject && subject.name || null;
+ res.teacher = teacher && teacher.name || null;
+ res.room = room && room.name || null;
+
+ result.push(withId(res, ['from', 'to', 'subject']));
+ }
+
+ return checkDuplicates(result);
+}
+
+module.exports = timetable;