Skip to content

Commit

Permalink
feat: 🎸 Hämta lärare och skolkontakter från api-skolplattfomen och vi…
Browse files Browse the repository at this point in the history
…sa lärarens namn i schemat (kolplattformen#589)

* feat: 🎸 Get list of teachers from api-skolplattfomen

* feat: 🎸 teachers and school contacts in hooks

* style: 💄 lint

* chore: 🤖 fakeData for matching some lessons with teachers

* feat: 🎸 Teacher's names in timetable (where available)

* test: 💍 fix failing tests (add mocks for new calls)
  • Loading branch information
kajetan-kazimierczak authored Dec 10, 2021
1 parent 0e95486 commit b7dbd35
Show file tree
Hide file tree
Showing 19 changed files with 449 additions and 5 deletions.
17 changes: 17 additions & 0 deletions libs/api-hjarntorget/lib/apiHjarntorget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
NewsItem,
Notification,
ScheduleItem,
SchoolContact,
Skola24Child,
Teacher,
TimetableEntry,
toMarkdown,
URLSearchParams,
Expand Down Expand Up @@ -248,6 +250,21 @@ export class ApiHjarntorget extends EventEmitter implements Api {
return Promise.resolve([])
}

public async getTeachers(child: EtjanstChild): Promise<Teacher[]> {
if (!this.isLoggedIn) {
throw new Error('Not logged in...')
}
return Promise.resolve([])
}

public async getSchoolContacts(child: EtjanstChild): Promise<SchoolContact[]> {
if (!this.isLoggedIn) {
throw new Error('Not logged in...')
}
return Promise.resolve([])
}


// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getNews(_child: EtjanstChild): Promise<NewsItem[]> {
if (!this.isLoggedIn) {
Expand Down
37 changes: 37 additions & 0 deletions libs/api-skolplattformen/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
ScheduleItem,
Skola24Child,
SSOSystem,
Teacher,
TimetableEntry,
SchoolContact,
URLSearchParams,
User,
wrap,
Expand Down Expand Up @@ -271,6 +273,39 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
return parse.classmates(data)
}

public async getTeachers(child: EtjanstChild): Promise<Teacher[]> {
if (this.isFake) return fakeResponse(fake.teachers(child))

const session = this.getRequestInit()

const schoolForms = (child.status || '').split(';')
let teachers: Teacher[] = []

for(let i = 0; i< schoolForms.length; i+=1){
const url = routes.teachers(child.sdsId, schoolForms[i])
// eslint-disable-next-line no-await-in-loop
const response = await this.fetch(`teachers_${schoolForms[i]}`, url, session)
// eslint-disable-next-line no-await-in-loop
const data = await response.json()
teachers = [
...teachers,
...parse.teachers(data)
]
}

return teachers
}

public async getSchoolContacts(child: EtjanstChild): Promise<SchoolContact[]> {
if(this.isFake) return fakeResponse(fake.schoolContacts(child))

const url = routes.schoolContacts(child.sdsId, child.schoolId || '')
const session = this.getRequestInit()
const response = await this.fetch('schoolContacts', url, session)
const data = await response.json()
return parse.schoolContacts(data)
}

public async getSchedule(
child: EtjanstChild,
from: DateTime,
Expand Down Expand Up @@ -524,6 +559,8 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
return parse.timetable(json, year, week, lang)
}



public async logout() {
this.isFake = false
this.personalNumber = undefined
Expand Down
2 changes: 2 additions & 0 deletions libs/api-skolplattformen/lib/fakeData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export * from './data'
export * from './children'
export * from './menu'
export * from './classmates'
export * from './teachers'
export * from './timetable'
export * from './schoolContacts'
export * from './news'
47 changes: 47 additions & 0 deletions libs/api-skolplattformen/lib/fakeData/schoolContacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { SchoolContact, Child } from '@skolplattformen/api';
import { children } from './children'

export const schoolContacts = (child: Child): SchoolContact[] => schoolContactData.get(child.id) ?? []

const [child1,child2] = children()

const schoolContactData = new Map<string, SchoolContact[]>([
[
child1.id, [
{
title: "Expedition",
name: null,
phone: "508 000 00",
email: "",
schoolName: "Vallaskolan",
className: null,
},
{
title: "Rektor",
name: "Alvar Sträng",
phone: "08-50800001",
email: "alvar.strang@edu.stockholm.se",
schoolName: null,
className: null,
}
]],
[
child2.id, [
{
title: "Expedition",
name: null,
phone: "508 000 00",
email: "",
schoolName: "Vallaskolan",
className: null,
},
{
title: "Rektor",
name: "Alvar Sträng",
phone: "08-50800001",
email: "alvar.strang@edu.stockholm.se",
schoolName: null,
className: null,
}
]]
])
81 changes: 81 additions & 0 deletions libs/api-skolplattformen/lib/fakeData/teachers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Teacher, Child } from '@skolplattformen/api';
import { children } from './children'

export const teachers = (child: Child): Teacher[] => teacherData.get(child.id) ?? []

const [child1,child2] = children()

const teacherData = new Map<string, Teacher[]>([
[
child1.id, [
{
id: 15662220,
firstname: "Cecilia",
sisId: null,
lastname: "Test",
email: "cecilia.test@edu.stockholm.se",
phoneWork: null,
active: true,
status: " S",
timeTableAbbreviation: 'CTE',
},
{
id: 15662221,
firstname: "Anna",
lastname: "Test",
sisId: null,
email: "anna.test@edu.stockholm.se",
phoneWork: '08000000',
active: true,
status: " GR",
timeTableAbbreviation: 'ATE',
},
{
id: 15662221,
firstname: "Greta",
lastname: "Test",
sisId: null,
email: null,
phoneWork: '08000001',
active: true,
status: " F",
timeTableAbbreviation: 'GTE',
},
]],
[
child2.id, [
{
id: 15662220,
firstname: "Cecilia",
sisId: null,
lastname: "Test",
email: "cecilia.test@edu.stockholm.se",
phoneWork: null,
active: true,
status: " S",
timeTableAbbreviation: 'CTE',
},
{
id: 15662221,
firstname: "Anna",
lastname: "Test",
sisId: null,
email: "anna.test@edu.stockholm.se",
phoneWork: '08000000',
active: true,
status: " GR",
timeTableAbbreviation: 'ATE',
},
{
id: 15662221,
firstname: "Greta",
lastname: "Test",
sisId: null,
email: null,
phoneWork: '08000001',
active: true,
status: " F",
timeTableAbbreviation: 'GTE',
},
]],
])
6 changes: 3 additions & 3 deletions libs/api-skolplattformen/lib/fakeData/timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const timetable = (child: Skola24Child): TimetableEntry[] => {
blockName: '',
dayOfWeek: 1,
location: '221',
teacher: 'KUr',
teacher: 'CTe',
timeEnd: '11:35:00',
timeStart: '09:40:00',
dateStart: '2021-04-12T09:40:00.000+02:00',
Expand Down Expand Up @@ -55,7 +55,7 @@ export const timetable = (child: Skola24Child): TimetableEntry[] => {
blockName: '',
dayOfWeek: 1,
location: '215',
teacher: 'HAl',
teacher: 'ATe, GTe',
timeEnd: '15:45:00',
timeStart: '14:40:00',
dateStart: '2021-04-12T14:40:00.000+02:00',
Expand All @@ -69,7 +69,7 @@ export const timetable = (child: Skola24Child): TimetableEntry[] => {
blockName: '',
dayOfWeek: 1,
location: '304',
teacher: 'DNi',
teacher: 'CTe,ATe',
timeEnd: '14:25:00',
timeStart: '13:40:00',
dateStart: '2021-04-12T13:40:00.000+02:00',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { EtjanstResponse } from '../'
import { schoolContacts } from '../schoolContacts'

let response: EtjanstResponse

beforeEach(() => {
response = {
"Success": true,
"Error": null,
"Data": [
{
"Title": "Expedition",
"Name": null,
"Phone": "508 000 00",
"Email": "",
"SchoolName": "Påhittade skolan",
"ClassName": null
},
{
"Title": "Rektor",
"Name": "Andersson, Anna Bella Cecilia",
"Phone": "08-508 000 00",
"Email": "anna.anderssonn@edu.stockholm.se",
"SchoolName": null,
"ClassName": null
}
]
}
})

it('parses teachers correctly', () => {
expect(schoolContacts(response)).toEqual([
{
title: 'Expedition',
name: null,
phone: '508 000 00',
email: '',
schoolName: 'Påhittade skolan',
className: null
},
{
title: 'Rektor',
name: 'Andersson, Anna Bella Cecilia',
phone: '08-508 000 00',
email: 'anna.anderssonn@edu.stockholm.se',
schoolName: null,
className: null
}
])
})
68 changes: 68 additions & 0 deletions libs/api-skolplattformen/lib/parse/__tests__/teachers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { EtjanstResponse } from '../'
import { teachers } from '../teachers'

let response: EtjanstResponse

beforeEach(() => {
response = {
"Success": true,
"Error": null,
"Data": [
{
"ID": 156735,
"BATCH": "GR",
"SIS_ID": "F154239A-EA4A-4C6C-A112-0B9581132E3D",
"USERNAME": "anna.andersson",
"SCHOOL_SIS_ID": "DE2E1293-0F40-4B91-9D91-1E99355DC257",
"EMAILADDRESS": null,
"STATUS": " GR",
"ERRORCODE": 0,
"FIRSTNAME": "Anna",
"LASTNAME": "Andersson",
"ACTIVE": true,
"TELWORK": "08 508 0000000"
},
{
"ID": 156690,
"BATCH": "GR",
"SIS_ID": "9EC59FCA-80AD-4774-AABD-427040207E33",
"USERNAME": "gunnar.grymm",
"SCHOOL_SIS_ID": "DE2E1293-0F40-4B91-9D91-1E99355DC257",
"EMAILADDRESS": "gunnar.grymm@edu.stockholm.se",
"STATUS": " F",
"ERRORCODE": 0,
"FIRSTNAME": "Gunnar",
"LASTNAME": "Grymm",
"ACTIVE": true,
"TELWORK": null
}
]
}
})

it('parses teachers correctly', () => {
expect(teachers(response)).toEqual([
{
id: 156735,
sisId: 'F154239A-EA4A-4C6C-A112-0B9581132E3D',
firstname: 'Anna',
lastname: 'Andersson',
email: null,
phoneWork: '08 508 0000000',
active: true,
status: ' GR',
timeTableAbbreviation: 'AAN'
},
{
id: 156690,
sisId: '9EC59FCA-80AD-4774-AABD-427040207E33',
firstname: 'Gunnar',
lastname: 'Grymm',
email: 'gunnar.grymm@edu.stockholm.se',
phoneWork: null,
active: true,
status: ' F',
timeTableAbbreviation: 'GGR'
},
])
})
2 changes: 2 additions & 0 deletions libs/api-skolplattformen/lib/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export * from './menu'
export * from './news'
export * from './notifications'
export * from './schedule'
export * from './schoolContacts'
export * from './teachers'
export * from './timetable'
export * from './user'
Loading

0 comments on commit b7dbd35

Please sign in to comment.