UNPKG

skola24-node

Version:

Library that provides convenient access to the Skola24 API.

75 lines 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Timetable { client; _getTimetableRenderKey; _getTimetableSelection; _renderTimetable; constructor(createApiRequest, client) { this.client = client; this._getTimetableRenderKey = createApiRequest("/get/timetable/render/key"); this._getTimetableSelection = createApiRequest("/get/timetable/selection"); this._renderTimetable = createApiRequest("/render/timetable"); } missing = (param) => `${param} is required but missing. Please provide a valid ${param} either in the 'data' parameter or ensure the client's config has a ${param} configured.`; addUnitGuid(data) { if (this.client.Config.UnitGuid == null && data.unitGuid == null) { throw new Error(this.missing("UnitGuid")); } return { ...data, unitGuid: data.unitGuid || this.client.Config.UnitGuid }; } async addSchoolYear(data) { if (!this.client.Config.SupplyOwnSchoolYear && !this.client.Config.SchoolYear) { const schoolYearResponse = await this.client.Utilities.getActiveSchoolYears({}); this.client.Config.SchoolYear = schoolYearResponse.activeSchoolYears[0].guid; } if (this.client.Config.SchoolYear == null && data.schoolYear == null) { throw new Error(this.missing("SchoolYear")); } return { ...data, schoolYear: data.schoolYear || this.client.Config.SchoolYear }; } async addRenderKey(data) { if (this.client.Config.SupplyOwnRenderKey && !data.renderKey) { throw new Error(this.missing("RenderKey")); } let clientSuppliedKey; if (!this.client.Config.SupplyOwnRenderKey) { const renderKeyResponse = await this.getTimetableRenderKey({}, {}); clientSuppliedKey = renderKeyResponse.key; } return { ...data, renderKey: data.renderKey || clientSuppliedKey }; } /** * Retrieves a render key. * * @param {RequestData.getTimetableRenderKey} data - An empty type. Always leave as `{}` * @param {AdditionalAxiosRequestConfig?} additionalConfig - Additional Axios configuration settings. */ getTimetableRenderKey = async (data, additionalConfig) => { return this._getTimetableRenderKey({ ...data }, additionalConfig); }; /** * Fetches selected timetable elements from the host based on the provided data, such as classes, teachers, rooms, and more. * * @param {RequestData.getTimetableSelection} data - Filters for timetable selections. * @param {AdditionalAxiosRequestConfig?} additionalConfig - Additional Axios configuration settings. */ getTimetableSelection = async (data, additionalConfig) => { const requestData = this.addUnitGuid(data); return this._getTimetableSelection({ hostName: this.client.Config.Host, ...requestData }, additionalConfig); }; /** * Retrieves a timetable. * * @param {RequestData.renderTimetable} data - Required information such as week and selection. * @param {AdditionalAxiosRequestConfig?} additionalConfig - Additional Axios configuration settings. */ renderTimetable = async (data, additionalConfig) => { data.height = data.height ?? 500; data.width = data.width ?? 500; const requestData = await this.addRenderKey(this.addUnitGuid(await this.addSchoolYear(data))); return this._renderTimetable({ host: this.client.Config.Host, ...requestData }, additionalConfig); }; } exports.default = Timetable; //# sourceMappingURL=Timetable.js.map