Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 Abscense registration for HT and Skolplattformen #573

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions libs/api-hjarntorget/lib/apiHjarntorget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
shibbolethLoginUrlBase,
verifyUrlBase,
wallMessagesUrl,
abscenseRegistrationUrl
} from './routes'
import parse from '@skolplattformen/curriculum'

Expand Down Expand Up @@ -591,6 +592,25 @@ export class ApiHjarntorget extends EventEmitter implements Api {
return statusChecker
}

public async registerAbscense(child: EtjanstChild, startDate: DateTime, endDate: DateTime): Promise<void> {
const body = {
attendeeId: child.id,
startDate: startDate.toFormat("yyyy-MM-dd HH:mm"),
endDate: endDate.toFormat("yyyy-MM-dd HH:mm"),
statusId: 27433608,
_submit: 'Save'
}

await this.fetch('register-abscense', abscenseRegistrationUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': "https://hjarntorget.goteborg.se/attendanceParentRegisterAbsence.do?attendeeId=" + child.id,
},
body: new URLSearchParams(body).toString(),
})
}

private async fakeMode(): Promise<LoginStatusChecker> {
this.isFake = true

Expand All @@ -603,4 +623,5 @@ export class ApiHjarntorget extends EventEmitter implements Api {
emitter.token = 'fake'
return emitter
}

}
2 changes: 2 additions & 0 deletions libs/api-hjarntorget/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion libs/api-hjarntorget/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const init = (
const cookieManager = ((cookieManagerImpl as RNCookieManager).get)
? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager)
: wrapToughCookie(cookieManagerImpl as ToughCookieJar)
return new ApiHjarntorget(fetchImpl as any, cookieManager, options)
return new ApiHjarntorget(fetchImpl, cookieManager, options)
}

export default init
1 change: 1 addition & 0 deletions libs/api-hjarntorget/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libs/api-skolplattformen/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
this.cookieManager = cookieManager
this.headers = {}
}
registerAbscense(child: EtjanstChild, startDate: DateTime, endDate: DateTime): Promise<void> {
throw new Error('Method not implemented.')
}

public getPersonalNumber(): string | undefined {
return this.personalNumber
Expand Down
2 changes: 2 additions & 0 deletions libs/api-skolplattformen/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions libs/api/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export interface Api extends EventEmitter {
getSchoolContacts(child: EtjanstChild): Promise<SchoolContact[]>
getSkola24Children(): Promise<Skola24Child[]>
getTimetable(child: Skola24Child, week: number, year: number, lang: Language): Promise<TimetableEntry[]>
registerAbscense(child: EtjanstChild, startDate: DateTime, endDate: DateTime): Promise<void>
logout(): Promise<void>
}
4 changes: 3 additions & 1 deletion libs/api/lib/features.ts
Original file line number Diff line number Diff line change
@@ -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