Skip to content

Commit

Permalink
feat: 🎸 Classmates (kolplattformen#14)
Browse files Browse the repository at this point in the history
Hopefully retrieves and parses class mates. I cannot confirm since,
according to Skolplattformen, my daughter has none.

✅ Closes: kolplattformen#7
  • Loading branch information
JohanObrink authored Dec 21, 2020
1 parent 9e3e176 commit a6ce6ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/children.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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)
}
9 changes: 7 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> }

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a6ce6ea

Please sign in to comment.