feat: 🎸 Classmates (#14)

Hopefully retrieves and parses class mates. I cannot confirm since,
according to Skolplattformen, my daughter has none.

 Closes: #7
This commit is contained in:
Johan Öbrink 2020-12-21 10:31:00 +01:00 committed by GitHub
parent 9e3e176198
commit a6ce6ea9f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import routes from './routes'
import {
CalendarItem, Child, Fetch, RequestInit,
CalendarItem, Child, Classmate, Fetch, RequestInit,
} from './types'
import { etjanst, child, calendarItem } from './parse'
@ -15,8 +15,12 @@ export const calendar = (fetch: Fetch, init?:RequestInit) => async (childId: str
const url = routes.calendar(childId)
const response = await fetch(url, init)
const data = await response.json()
console.log(etjanst(data))
return etjanst(data).map(calendarItem)
}
// export const details = (_fetch: Fetch) => async (_id: string): Promise<Child> => ({})
export const classmates = (fetch: Fetch, init?:RequestInit) => async (childId: string): Promise<Classmate[]> => {
const url = routes.classmates(childId)
const response = await fetch(url, init)
const data = await response.json()
return etjanst(data)
}

View File

@ -3,9 +3,9 @@ import {
checkStatus, getSessionCookie, login, LoginStatus,
} from './login'
import {
CalendarItem, Child, Fetch, RequestInit,
CalendarItem, Child, Classmate, Fetch, RequestInit,
} from './types'
import { calendar, list } from './children'
import { calendar, classmates, list } from './children'
interface AsyncishFunction { (): void | Promise<void> }
@ -55,6 +55,11 @@ export class Api extends EventEmitter {
return data
}
async getClassmates(childId: string): Promise<Classmate[]> {
const data = await classmates(this.fetch, this.session)(childId)
return data
}
async logout() {
this.session = undefined
await this.clearCookies()