feat: 🎸 Abscense registration for HT and Skolplattformen

This commit is contained in:
Viktor Sarström 2021-12-02 09:54:04 +01:00
parent 112374b345
commit 411053c5d0
7 changed files with 30 additions and 1 deletions

View File

@ -47,6 +47,7 @@ import {
shibbolethLoginUrlBase,
verifyUrlBase,
wallMessagesUrl,
abscenseRegistrationUrl
} from './routes'
function getDateOfISOWeek(week: number, year: number) {
@ -571,6 +572,22 @@ export class ApiHjarntorget extends EventEmitter implements Api {
return statusChecker
}
public async registerAbscense(child: EtjanstChild, startDate: Date, endDate: Date): Promise<void> {
const body = {
attendeeId: child.id,
startDate: startDate,
endDate: endDate,
statusId: 27433608,
_submit: 'Register+the+whole+day'
}
this.fetch('register-abscense', abscenseRegistrationUrl, {
method: 'POST',
body: new URLSearchParams(body).toString(),
})
}
private async fakeMode(): Promise<LoginStatusChecker> {
this.isFake = true
@ -583,4 +600,5 @@ export class ApiHjarntorget extends EventEmitter implements Api {
emitter.token = 'fake'
return emitter
}
}

View File

@ -4,4 +4,6 @@ export const features: Features = {
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: false,
FOOD_MENU: false,
CLASS_LIST: false,
ABSCENE_REGISTRATION_SMS: false,
ABSCENE_REGISTRATION_FORM: true
}

View File

@ -15,6 +15,7 @@ export const wallMessagesUrl = 'https://hjarntorget.goteborg.se/api/wall/events?
export const beginLoginUrl = 'https://hjarntorget.goteborg.se'
export const calendarsUrl = 'https://hjarntorget.goteborg.se/pp/system/calendar/cal_events.jsp'
export const calendarEventUrl = (calendarId: string, startDate: string, endDate: string) => `${calendarsUrl}?order_by=start_date&show_cal_ids=${calendarId}&mode=separate&filter_start_date=${startDate}&filter_end_date=${endDate}&search_for=`
export const abscenseRegistrationUrl = 'https://hjarntorget.goteborg.se/attendanceParentSubmitAbsence.do'
export const shibbolethLoginUrlBase = (beginLoginRedirectUrl: string) => {
const returnUrlStart = beginLoginRedirectUrl.indexOf('return=') + 'return='.length

View File

@ -79,6 +79,9 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
this.cookieManager = cookieManager
this.headers = {}
}
registerAbscense(child: EtjanstChild, startDate: Date, endDate: Date): Promise<boolean> {
throw new Error('Method not implemented.')
}
public getPersonalNumber(): string | undefined {
return this.personalNumber

View File

@ -4,4 +4,6 @@ export const features: Features = {
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: true,
FOOD_MENU: true,
CLASS_LIST: true,
ABSCENE_REGISTRATION_SMS: true,
ABSCENE_REGISTRATION_FORM: false
}

View File

@ -32,5 +32,6 @@ export interface Api extends EventEmitter {
getSchedule(child: EtjanstChild, from: DateTime, to: DateTime): Promise<ScheduleItem[]>
getSkola24Children(): Promise<Skola24Child[]>
getTimetable(child: Skola24Child, week: number, year: number, lang: Language): Promise<TimetableEntry[]>
registerAbscense(child: EtjanstChild, startDate: Date, endDate: Date): Promise<void>
logout(): Promise<void>
}

View File

@ -1,7 +1,9 @@
export interface Features {
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: boolean
FOOD_MENU: boolean,
CLASS_LIST: boolean
CLASS_LIST: boolean,
ABSCENE_REGISTRATION_SMS: boolean,
ABSCENE_REGISTRATION_FORM: boolean,
}
export type FeatureType = keyof Features