diff options
author | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
commit | 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch) | |
tree | 75be5fba4368472fb11c8015aee026b2b9a71888 /school/node_modules/pronote-api/src/fetch/absences.js | |
parent | 8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff) | |
download | pluralconnect-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 'school/node_modules/pronote-api/src/fetch/absences.js')
-rw-r--r-- | school/node_modules/pronote-api/src/fetch/absences.js | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/school/node_modules/pronote-api/src/fetch/absences.js b/school/node_modules/pronote-api/src/fetch/absences.js deleted file mode 100644 index 9c1ac02..0000000 --- a/school/node_modules/pronote-api/src/fetch/absences.js +++ /dev/null @@ -1,114 +0,0 @@ -const { getPeriodBy } = require('../data/periods'); -const { withId, checkDuplicates } = require('../data/id'); - -const getAbsences = require('./pronote/absences'); - -// eslint-disable-next-line complexity -async function absences(session, user, period = null, from = null, to = null, type = null) -{ - const result = { - absences: [], - delays: [], - punishments: [], - other: [], - totals: [] - }; - - const p = getPeriodBy(session, !period && !type && from && to ? 'Trimestre 1' : period, type); - const absences = await getAbsences(session, user, p, from || p.from, to || p.to); - if (!absences) { - return null; - } - - for (const event of absences.events) { - // eslint-disable-next-line default-case - switch (event.type) { - case 'absence': - result.absences.push(withId({ - from: event.from, - to: event.to, - justified: event.justified, - solved: event.solved, - hours: event.hours, - reason: event.reasons.length && event.reasons[0].name || '' - }, ['from', 'to'])); - break; - case 'delay': - result.delays.push(withId({ - date: event.date, - justified: event.justified, - solved: event.solved, - justification: event.justification, - minutesMissed: event.duration, - reason: event.reasons.length && event.reasons[0].name || '' - }, ['data', 'minutesMissed'])); - break; - case 'punishment': - // eslint-disable-next-line no-case-declarations - let detention = null; - if (event.nature.type === 1) { - const schedule = event.schedule[0]; - const hour = session.params.firstHour.getHours() + schedule.position / session.params.ticksPerHour; - - const from = new Date(schedule.date.getTime()); - const to = new Date(schedule.date.getTime()); - - from.setHours(from.getHours() + hour); - to.setHours(to.getHours() + hour); - to.setMinutes(to.getMinutes() + schedule.duration); - - detention = { from, to }; - } - - result.punishments.push(withId({ - date: event.date, - isExclusion: event.isExclusion, - isDuringLesson: !event.isNotDuringLesson, - homework: event.homework, - circumstances: event.circumstances, - giver: event.giver.name, - reason: event.reasons.length && event.reasons[0].name || '', - detention - }, ['data'])); - break; - case 'other': - result.other.push(withId({ - kind: event.name, - date: event.date, - giver: event.giver.name, - comment: event.comment, - subject: event.subject && event.subject.name || null - }, ['kind', 'date'])); - break; - } - } - - Object.values(result).forEach(checkDuplicates); - - if (absences.subjects) { - for (const subject of absences.subjects) { - if (subject.inGroup) { - continue; - } - - const res = parseSubject(subject); - if (subject.group) { - res.subs = absences.subjects.filter(s => s.inGroup === subject.group).map(s => parseSubject(s)); - } - - result.totals.push(res); - } - } - - return result; -} - -function parseSubject(subject) { - return { - subject: subject.name, - hoursAssisted: subject.hoursAssisted, - hoursMissed: subject.hoursMissed - }; -} - -module.exports = absences; |