Skip to content

Commit

Permalink
Add getCurrentSchoolyear()
Browse files Browse the repository at this point in the history
  • Loading branch information
nkilders committed Feb 12, 2024
1 parent 2c51a44 commit 4b49fb1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ test('should convertUntisTime converted time', () => {
});

cases(
'should method return result',
'should JSON RPC method return result',
async ({ name, method, validate, post }) => {
const untis = createInstance();

Expand Down Expand Up @@ -551,6 +551,18 @@ cases(
validate: false,
post: 0,
},
{
name: 'getCurrentSchoolyear',
method: 'getCurrentSchoolyear',
validate: false,
post: 0,
},
{
name: 'getCurrentSchoolyear',
method: 'getCurrentSchoolyear',
validate: true,
post: 1,
},
{
name: 'getTimegrid',
method: 'getTimegridUnits',
Expand Down
18 changes: 18 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,24 @@ export class Base {
return await this._request('getStatusData', {}, validateSession);
}

/**
* Get the current school year
* @param [validateSession=true]
* @returns {Promise.<SchoolYear>}
*/
async getCurrentSchoolyear(validateSession = true): Promise<SchoolYear> {
const data = await this._request<InternalSchoolYear>('getCurrentSchoolyear', {}, validateSession);

if (!data) throw new Error('Failed to retrieve current school year');

return {
name: data.name,
id: data.id,
startDate: Base.convertUntisDate(data.startDate),
endDate: Base.convertUntisDate(data.endDate),
};
}

/**
* Convert a JS Date Object to a WebUntis date string
* @param {Date} date
Expand Down

0 comments on commit 4b49fb1

Please sign in to comment.