summaryrefslogtreecommitdiff
path: root/includes/external/school/node_modules/pronote-api/src/server/context.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/server/context.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/server/context.js')
-rw-r--r--includes/external/school/node_modules/pronote-api/src/server/context.js73
1 files changed, 73 insertions, 0 deletions
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;