From 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 23 Feb 2023 19:34:56 +0100 Subject: Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated) --- .../node_modules/pronote-api/src/server/context.js | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 includes/external/school/node_modules/pronote-api/src/server/context.js (limited to 'includes/external/school/node_modules/pronote-api/src/server/context.js') diff --git a/includes/external/school/node_modules/pronote-api/src/server/context.js b/includes/external/school/node_modules/pronote-api/src/server/context.js new file mode 100644 index 0000000..9f34442 --- /dev/null +++ b/includes/external/school/node_modules/pronote-api/src/server/context.js @@ -0,0 +1,73 @@ +function common(session) { + return { + params: () => session.params, + user: () => session.user, + + keepAlive: async () => { + await session.keepAlive(); + return true; + }, + logout: async () => { + await session.logout(); + return true; + }, + + setKeepAlive: async ({ enabled }) => { + await session.setKeepAlive(enabled); + return enabled; + } + }; +} + +function student(session) { + return { + timetable: ({ from, to }) => session.timetable(from, to), + marks: ({ period }) => session.marks(period), + evaluations: ({ period }) => session.evaluations(period), + absences: ({ period, from, to }) => session.absences(period, from, to), + infos: () => session.infos(), + contents: ({ from, to }) => session.contents(from, to), + homeworks: ({ from, to }) => session.homeworks(from, to), + menu: ({ from, to }) => session.menu(from, to), + files: () => session.files() + }; +} + +function parent(session) { + function getStudent(student) { + for (const s of session.user.students) { + if (s.id === student || s.name === student) { + return s; + } + } + + return null; + } + + return { + timetable: ({ student, from, to }) => session.timetable(getStudent(student), from, to), + marks: ({ student, period }) => session.marks(getStudent(student), period), + evaluations: ({ student, period }) => session.evaluations(getStudent(student), period), + absences: ({ student, period, from, to }) => session.absences(getStudent(student), period, from, to), + infos: ({ student }) => session.infos(getStudent(student)), + contents: ({ student, from, to }) => session.contents(getStudent(student), from, to), + homeworks: ({ student, from, to }) => session.homeworks(getStudent(student), from, to), + menu: ({ student, from, to }) => session.menu(getStudent(student), from, to), + files: ({ student }) => session.files(getStudent(student)) + }; +} + +function getContext(session) { + const result = common(session); + + switch (session.type.name) { + case 'student': + return { ...result, ...student(session) }; + case 'parent': + return { ...result, ...parent(session) }; + default: + return result; + } +} + +module.exports = getContext; -- cgit