@@ -16,7 +16,7 @@ class MagisterApi {
1616
1717 this . updateApiCredentials ( ) ;
1818
19- this . permissions = await this . updateApiPermissions ( ) ;
19+ await this . updateAccountInfo ( ) ;
2020 this . gatherStart = dates . gatherStart ;
2121 this . gatherEarlyStart = dates . gatherEarlyStart ;
2222 this . gatherEnd = dates . gatherEnd ;
@@ -47,10 +47,15 @@ class MagisterApi {
4747 }
4848 }
4949
50- async updateApiPermissions ( ) {
50+ async updateAccountInfo ( ) {
5151 return new Promise ( async ( resolve ) => {
52- this . permissions = ( await new MagisterApiRequestAccount ( ) . get ( ) ) ?. Groep ?. [ 0 ] ?. Privileges ?. filter ( p => p . AccessType . includes ( 'Read' ) ) . map ( p => p . Naam ) ;
53- resolve ( this . permissions ) ;
52+ const account = await this . accountInfo ( ) ;
53+ this . permissions = account ?. Groep ?. [ 0 ] ?. Privileges ?. filter ( p => p . AccessType . includes ( 'Read' ) ) . map ( p => p . Naam ) ;
54+ this . uuid = account ?. UuId ;
55+
56+ const calendarFeatures = await this . getCalendarFeatures ( ) ;
57+ this . calendarFeatures = calendarFeatures || { } ;
58+ resolve ( { permissions : this . permissions , uuid : this . uuid , calendarFeatures : this . calendarFeatures } ) ;
5459 } ) ;
5560 }
5661
@@ -111,6 +116,18 @@ class MagisterApi {
111116 return new MagisterApiRequestKwtRegistration ( id ) . delete ( ) ;
112117 }
113118
119+ getCalendarFeatures ( ) {
120+ return new MagisterApiRequestCalendarFeatures ( ) . get ( ) ;
121+ }
122+
123+ additionalAppointments ( start = dates . now , end = dates . now ) {
124+ return new MagisterApiRequestAdditionalAppointments ( start , end ) . get ( ) ;
125+ }
126+
127+ enrollAdditionalAppointment ( path ) {
128+ return new MagisterApiRequestEnrollAdditionalAppointment ( path ) . post ( ) ;
129+ }
130+
114131 gradesRecent ( size = 25 ) {
115132 return new MagisterApiRequestGradesRecent ( size ) . get ( ) ;
116133 }
@@ -155,6 +172,7 @@ class MagisterApi {
155172class MagisterApiRequest {
156173 identifier ;
157174 path ;
175+ href ;
158176
159177 constructor ( ) {
160178 }
@@ -165,13 +183,13 @@ class MagisterApiRequest {
165183
166184 if ( magisterApi . useSampleData && this . sample ) {
167185 return Promise . resolve ( this . sample ) ;
168- } else if ( ! this . identifier || ! this . path ) {
169- return Promise . reject ( ) ;
186+ } else if ( ! this . identifier || ( ! this . path && ! this . href ) ) {
187+ return Promise . reject ( "Invalid API request: no identifier or path/href specified." ) ;
170188 } else if ( magisterApi . cache [ this . identifier ] && ! magisterApi . cache [ this . identifier ] . then ) {
171189 return Promise . resolve ( magisterApi . cache [ this . identifier ] ) ;
172190 } else {
173191 return this . #fetchWrapper(
174- `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` ,
192+ ( this . href || `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` ) ,
175193 options
176194 ) ;
177195 }
@@ -182,7 +200,7 @@ class MagisterApiRequest {
182200 if ( ! window . location . pathname . includes ( 'magister' ) ) reject ( ) ;
183201
184202 let res = await fetch (
185- `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) ,
203+ ( this . href || `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` ) . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) . replace ( / ( \$ U U I D ) / gi , magisterApi . uuid ) ,
186204 {
187205 method : 'PUT' ,
188206 body : JSON . stringify ( body ) ,
@@ -205,7 +223,7 @@ class MagisterApiRequest {
205223 if ( ! window . location . pathname . includes ( 'magister' ) ) reject ( ) ;
206224
207225 let res = await fetch (
208- `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) ,
226+ ( this . href || `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` ) . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) . replace ( / ( \$ U U I D ) / gi , magisterApi . uuid ) ,
209227 {
210228 method : 'POST' ,
211229 body : JSON . stringify ( body ) ,
@@ -228,7 +246,7 @@ class MagisterApiRequest {
228246 if ( ! window . location . pathname . includes ( 'magister' ) ) reject ( ) ;
229247
230248 let res = await fetch (
231- `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) ,
249+ ( this . href || `https://${ magisterApi . schoolName } .magister.net/${ this . path } ` ) . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) . replace ( / ( \$ U U I D ) / gi , magisterApi . uuid ) ,
232250 {
233251 method : 'DELETE' ,
234252 body : JSON . stringify ( body ) ,
@@ -286,7 +304,7 @@ class MagisterApiRequest {
286304 }
287305
288306 try {
289- let res = await fetch ( url . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) , {
307+ let res = await fetch ( url . replace ( / ( \$ U S E R I D ) / gi, magisterApi . userId ) . replace ( / ( \$ U U I D ) / gi , magisterApi . uuid ) , {
290308 headers : {
291309 Authorization : magisterApi . userToken ,
292310 'X-Request-Source' : 'study-tools'
@@ -411,6 +429,30 @@ class MagisterApiRequestKwtRegistration extends MagisterApiRequest {
411429 }
412430}
413431
432+ class MagisterApiRequestCalendarFeatures extends MagisterApiRequest {
433+ constructor ( start , end ) {
434+ super ( ) ;
435+ this . identifier = `calendarFeatures` ;
436+ this . href = `https://calendar.magister.net/api/user/$UUID/features` ;
437+ }
438+ }
439+
440+ class MagisterApiRequestAdditionalAppointments extends MagisterApiRequest {
441+ constructor ( start , end ) {
442+ super ( ) ;
443+ this . identifier = `additionalAppointments${ start ?. toISOString ( ) } ${ end ?. toISOString ( ) } ` ;
444+ this . href = `https://calendar.magister.net/api/user/$UUID/additional-appointments?start=${ start ?. toISOString ( ) . substring ( 0 , 19 ) } %2B00:00&end=${ end ?. toISOString ( ) . substring ( 0 , 19 ) } %2B00:00` ;
445+ }
446+ }
447+
448+ class MagisterApiRequestEnrollAdditionalAppointment extends MagisterApiRequest {
449+ constructor ( path ) {
450+ super ( ) ;
451+ this . identifier = `additionalAppointmentsEnroll${ path } ` ;
452+ this . href = `https://calendar.magister.net/${ path } ` ;
453+ }
454+ }
455+
414456class MagisterApiRequestGradesRecent extends MagisterApiRequest {
415457 constructor ( size = 25 ) {
416458 super ( ) ;
0 commit comments