summaryrefslogtreecommitdiff
path: root/school/node_modules/pronote-api/src/fetch/files.js
blob: 7703ee43738e01fe63797aef960b38052cdeaf9d (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
const { parseDate } = require('../data/dates');
const { getFileURL } = require('../data/files');
const { withId, checkDuplicates } = require('../data/id');

const getFiles = require('./pronote/files');

async function files(session, user) {
    const files = await getFiles(session, user);
    if (!files) {
        return null;
    }

    const result = [];

    const subjects = {};
    for (const subject of files.listeMatieres.V) {
        subjects[subject.N] = subject.L;
    }

    for (const file of files.listeRessources.V) {
        result.push(withId({
            time: parseDate(file.date.V),
            subject: subjects[file.matiere.V.N],
            name: file.ressource.V.L,
            url: getFileURL(session, { id: file.ressource.V.N, name: file.ressource.V.L, type: file.ressource.V.G })
        }, 'subject', 'name'));
    }

    return checkDuplicates(result);
}

module.exports = files;