summaryrefslogtreecommitdiff
path: root/alarm/node_modules/pronote-api/src/fetch/evaluations.js
blob: dca1b9f8e75beaff4b4b408d0b2b4ee9281f09d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { getPeriodBy } = require('../data/periods');
const { withId, checkDuplicates } = require('../data/id');

const getEvaluations = require('./pronote/evaluations');

async function evaluations(session, user, period = null, type = null)
{
    const evaluations = await getEvaluations(session, user, getPeriodBy(session, period, type));
    if (!evaluations) {
        return null;
    }

    const result = [];

    if (!evaluations) {
        return null;
    }

    for (const evaluation of evaluations) {
        let subject = result.find(s => s.name === evaluation.subject.name);
        if (!subject) {
            const { position, name, color } = evaluation.subject;
            subject = {
                position,
                name,
                teacher: evaluation.teacher.name,
                color,
                evaluations: []
            };

            result.push(subject);
        }

        subject.evaluations.push(withId({
            name: evaluation.name,
            date: evaluation.date,
            coefficient: evaluation.coefficient,
            levels: evaluation.acquisitionLevels.map(({ name, position, value, item, domain, pillar }) => ({
                name: item && item.name || domain.name,
                position,
                value: {
                    short: value,
                    long: name
                },
                prefixes: !pillar.prefixes[0] ? [] : pillar.prefixes
            }))
        }, ['name', 'date'], subject.name));
    }

    result.forEach(s => checkDuplicates(s.evaluations));

    result.sort((a, b) => a.position - b.position);
    result.forEach(s => {
        s.evaluations.forEach(e => {
            e.levels.sort((a, b) => a.position - b.position);
            e.levels.forEach(l => delete l.position);
        });

        return delete s.position;
    });

    return result;
}

module.exports = evaluations;