UNPKG

ecoledirecte.js

Version:

Good-looking client for EcoleDirecte's private API.

34 lines (33 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTimetable = void 0; const v3_1 = require("ecoledirecte-api-types/v3"); const util_1 = require("../util"); async function getTimetable(account, dates = Date.now(), context = {}) { if (!account.hasModule("EDT")) { throw new Error("Account does not have timetable enabled"); } if (!Array.isArray(dates)) dates = [dates]; if (!dates[1]) dates[1] = dates[0]; const startDate = new Date(dates[0]); const endDate = new Date(dates[1]); if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { throw new Error("Invalid dates"); } if (startDate > endDate) throw new Error("Start date is after end date"); const body = await (0, util_1.makeRequest)({ method: "POST", path: v3_1.Routes.timetable(account.__raw.typeCompte, account.edId), body: { token: account.token, dateDebut: (0, util_1.toISODate)(startDate), dateFin: (0, util_1.toISODate)(endDate), }, guard: true, }, { userId: account.edId, action: "getTimetable", ...context }); return body; } exports.getTimetable = getTimetable;