SchoolUtils / WebUntis

JavaScript WebUntis API Client
https://webuntis.noim.me/
MIT License
159 stars 21 forks source link

Get request of timetable throws error #49

Closed se7en241 closed 3 years ago

se7en241 commented 3 years ago

Hi, I am using the WebUntis plugin as part of a module of the magic mirror and it is throwing error like this: /home/pi/MagicMirror/modules/MMM-untis/node_modules/webuntis/index.js:233 ...additionalOptions, ^^^ SyntaxError: Unexpected token ... at Object.exports.runInThisContext (vm.js:78:16) at Module._compile (module.js:543:28) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object. (/home/pi/MagicMirror/modules/MMM-untis/node_helper.js:2:15) at Object. (/home/pi/MagicMirror/modules/MMM-untis/node_helper.js:132:3)

If I "correct" the syntax by removing the "..." then the code works, but the timetable request is not considering the range provided by additionalOptions.startDate and additionalOptions.endDate: async _timetableRequest(id, type, startDate, endDate, validateSession = true) { const additionalOptions = {}; if (startDate) { additionalOptions.startDate = this.convertDateToUntis(startDate); } if (endDate) { additionalOptions.endDate = this.convertDateToUntis(endDate); }

    return this._request(
        'getTimetable',
        {
            options: {
                id: new Date().getTime(),
                element: {
                    id,
                    type
                },
                additionalOptions,
                showLsText: true,
                showStudentgroup: true,
                showLsNumber: true,
                showSubstText: true,
                showInfo: true,
                showBooking: true,
                klasseFields: ['id', 'name', 'longname', 'externalkey'],
                roomFields: ['id', 'name', 'longname', 'externalkey'],
                subjectFields: ['id', 'name', 'longname', 'externalkey'],
                teacherFields: ['id', 'name', 'longname', 'externalkey']
            }
        },
        validateSession
    );
}

Any idea how to fix it? Regards se7en241

luwol03 commented 3 years ago

which node version do you have? You can check it by typing the following into you preferred shell.

node -v
se7en241 commented 3 years ago

it is 6.10

se7en241 commented 3 years ago

handing the parameters in the following way, seems to work as a work around:

    return this._request(
        'getTimetable',
        {
            options: {
                id: new Date().getTime(),
                element: {
                    id,
                    type
                },
                startDate:additionalOptions.startDate,
                endDate:additionalOptions.endDate,
                showLsText: true,
                showStudentgroup: true,
luwol03 commented 3 years ago

it is 6.10

You need at minimum v8.3 in order to use the spread operator for rest (the thing). But I recommend you to use at minimum v14.x because it’s the current LTS version.

se7en241 commented 3 years ago

Thanx