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:
parent
9e3e176198
commit
a6ce6ea9f6
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue