From 084c713383266743016dfe1155be509ee5b70fb2 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sat, 2 Oct 2021 22:46:08 +0200 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Kontaktinformation?= =?UTF-8?q?=20till=20l=C3=A4rare=20och=20skola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/routes.ts b/lib/routes.ts index 1c97f3c..b0d9e03 100644 --- a/lib/routes.ts +++ b/lib/routes.ts @@ -20,6 +20,12 @@ export const calendar = (childId: string) => export const classmates = (childId: string) => `${urlLoggedIn}/contacts/GetStudentsByClass?studentId=${childId}` +export const teachers = (childId: string, schoolForm: string) => + `${urlLoggedIn}/contacts/GetTeachersByStudent?studentId=${childId}&schoolForm=${schoolForm}` + +export const schoolContacts = (childId: string, schoolId: string) => + `${urlLoggedIn}/contacts/GetSchoolContacts?schoolId=${schoolId}&studentId=${childId}&schoolForm=Klasslista` + export const user = 'https://etjanst.stockholm.se/vardnadshavare/base/getuserdata' From dea073860693a72b2af177ae0c913f508fa73b56 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 00:33:13 +0200 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Get=20teachers=20for?= =?UTF-8?q?=20GR=20and=20schoolContacts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devrun.js | 11 ++++++- lib/api.ts | 23 ++++++++++++++ lib/fakeData.ts | 60 ++++++++++++++++++++++++++++++++++++- lib/parse/index.ts | 2 ++ lib/parse/schoolContacts.ts | 22 ++++++++++++++ lib/parse/teachers.ts | 30 +++++++++++++++++++ lib/types.ts | 29 ++++++++++++++++++ 7 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 lib/parse/schoolContacts.ts create mode 100644 lib/parse/teachers.ts diff --git a/devrun.js b/devrun.js index 05897db..410a515 100644 --- a/devrun.js +++ b/devrun.js @@ -66,6 +66,15 @@ async function run() { const classmates = await api.getClassmates(children[0]) console.log(classmates) */ + console.log('teachers') + const teachers = await api.getTeachers(children[0]) + console.log(teachers) + + console.log('schoolContacts') + const schoolContacts = await api.getSchoolContacts(children[0]) + console.log(schoolContacts) + + /* try { console.log('schedule') const schedule = await api.getSchedule(children[1], DateTime.local(), DateTime.local().plus({ week: 1 })) @@ -89,7 +98,7 @@ async function run() { } catch (error) { console.error(error) } - + */ /* console.log('news') const news = await api.getNews(children[0]) diff --git a/lib/api.ts b/lib/api.ts index 3176487..ebbd415 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -9,6 +9,7 @@ import { AuthTicket, CalendarItem, Classmate, + Teacher, CookieManager, Fetch, MenuItem, @@ -26,6 +27,7 @@ import * as routes from './routes' import * as parse from './parse/index' import wrap, { Fetcher, FetcherOptions } from './fetcher' import * as fake from './fakeData' +import { SchoolContact } from '.' const fakeResponse = (data: T): Promise => new Promise((res) => setTimeout(() => res(data), 200 + Math.random() * 800)) @@ -253,6 +255,27 @@ export class Api extends EventEmitter { return parse.classmates(data) } + public async getTeachers(child: EtjanstChild): Promise { + if (this.isFake) return fakeResponse(fake.teachers(child)) + + const schoolForm = 'GR' + const url = routes.teachers(child.sdsId, schoolForm) + const session = this.getRequestInit() + const response = await this.fetch('teaches', url, session) + const data = await response.json() + return parse.teachers(data) + } + + public async getSchoolContacts(child: EtjanstChild): Promise { + 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, diff --git a/lib/fakeData.ts b/lib/fakeData.ts index 0b2a32f..82db1c4 100644 --- a/lib/fakeData.ts +++ b/lib/fakeData.ts @@ -1,8 +1,10 @@ /* eslint-disable max-len */ +import { SchoolContact } from '.' import { CalendarItem, Child, Classmate, + Teacher, EtjanstChild, MenuItem, NewsItem, @@ -233,6 +235,56 @@ const data: any = { className: '2B', }, ], + teachers: [ + { + id: 15662220, + firstname: "Cecilia", + lastname: "Test", + email: "cecilia.test@edu.stockholm.se", + phoneWork: null, + active: true, + status: " S", + timeTableAbbreviation: 'CTE', + }, + { + id: 15662221, + firstname: "Anna", + lastname: "Test", + email: "anna.test@edu.stockholm.se", + phoneWork: '08000000', + active: true, + status: " GR", + timeTableAbbreviation: 'ATE', + }, + { + id: 15662221, + firstname: "Greta", + lastname: "Test", + email: null, + phoneWork: '08000001', + active: true, + status: " F", + timeTableAbbreviation: 'GTE', + } + ], + schoolContacts: [ + { + 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, + } + ], news: [ { id: 'asdfasdfasdfw', @@ -1126,6 +1178,12 @@ export const skola24Children = (): Skola24Child[] => [ export const classmates = (child: EtjanstChild): Classmate[] => data[child.id].classmates +export const teachers = (child:EtjanstChild): Teacher[] => + data[child.id].teachers + +export const schoolContacts = (child: EtjanstChild): SchoolContact[] => + data[child.id].schoolContacts + export const news = (child: Child): NewsItem[] => data[child.id].news export const calendar = (child: Child): CalendarItem[] => @@ -1599,5 +1657,5 @@ export const timetable = (child: Skola24Child): TimetableEntry[] => { dateStart: '2021-04-16T10:40:00.000+02:00', dateEnd: '2021-04-16T11:35:00.000+02:00', } - ] + ] } diff --git a/lib/parse/index.ts b/lib/parse/index.ts index 89eedf1..092b94e 100644 --- a/lib/parse/index.ts +++ b/lib/parse/index.ts @@ -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' diff --git a/lib/parse/schoolContacts.ts b/lib/parse/schoolContacts.ts new file mode 100644 index 0000000..823052c --- /dev/null +++ b/lib/parse/schoolContacts.ts @@ -0,0 +1,22 @@ +import { etjanst } from './etjanst' +import { SchoolContact } from '../types' + +export const schoolContact = ({ + title, + name, + phone, + email, + schoolName, + className, +}: any): SchoolContact => ({ + title, + name, + phone, + email, + schoolName, + className, +}) + + +export const schoolContacts = (data: any): SchoolContact[] => + etjanst(data).map(schoolContact) \ No newline at end of file diff --git a/lib/parse/teachers.ts b/lib/parse/teachers.ts new file mode 100644 index 0000000..89d9452 --- /dev/null +++ b/lib/parse/teachers.ts @@ -0,0 +1,30 @@ +import { etjanst } from './etjanst' +import { Teacher } from '../types' + +export const teacher = ({ + id, + sisId, + firstname, + lastname, + emailaddress, + telWork, + active, + status, +}: any): Teacher => ({ + id, + sisId, + firstname, + lastname, + email: emailaddress, + phoneWork: telWork, + active, + status, + timeTableAbbreviation: abbreviate(firstname, lastname) +}) + +const abbreviate = (firstname?: string, lastname?: string): string => { + return `${firstname?.substr(0,1)}${lastname?.substr(0,2)}`.toUpperCase() +} + +export const teachers = (data: any): Teacher[] => + etjanst(data).map(teacher) diff --git a/lib/types.ts b/lib/types.ts index 5f779ad..63e0218 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -112,6 +112,35 @@ export interface Guardian { address?: string } +/** + * @export + * @interface Teacher + */ +export interface Teacher { + id: number + sisId: string + firstname: string + lastname: string + email?: string + phoneWork?: string + active: boolean + status: string + timeTableAbbreviation: string +} + +/** + * @export + * @interface SchoolContact + */ +export interface SchoolContact { + title?: string + name?: string + phone?: string + email?: string + schoolName: string + className: string +} + /** *

A news item from the school, for example a weekly news letter

* @export From 45f389c41588f1b9c27c2913c5f779184f86f721 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 00:58:11 +0200 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api.ts | 5 +++-- lib/fakeData.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index ebbd415..52ab88a 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -9,7 +9,6 @@ import { AuthTicket, CalendarItem, Classmate, - Teacher, CookieManager, Fetch, MenuItem, @@ -18,7 +17,9 @@ import { RequestInit, ScheduleItem, User, + SchoolContact, Skola24Child, + Teacher, EtjanstChild, SSOSystem, TimetableEntry @@ -27,7 +28,7 @@ import * as routes from './routes' import * as parse from './parse/index' import wrap, { Fetcher, FetcherOptions } from './fetcher' import * as fake from './fakeData' -import { SchoolContact } from '.' + const fakeResponse = (data: T): Promise => new Promise((res) => setTimeout(() => res(data), 200 + Math.random() * 800)) diff --git a/lib/fakeData.ts b/lib/fakeData.ts index 82db1c4..120f5a3 100644 --- a/lib/fakeData.ts +++ b/lib/fakeData.ts @@ -1,16 +1,16 @@ /* eslint-disable max-len */ -import { SchoolContact } from '.' import { CalendarItem, Child, Classmate, - Teacher, EtjanstChild, MenuItem, NewsItem, Notification, ScheduleItem, + SchoolContact, Skola24Child, + Teacher, TimetableEntry, User, } from './types' From 846a4b3a462edcef8c69dcfd85e197036648b268 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 01:09:51 +0200 Subject: [PATCH 4/9] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20moved=20code=20a?= =?UTF-8?q?round=20to=20satisfy=20linter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/parse/teachers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/parse/teachers.ts b/lib/parse/teachers.ts index 89d9452..2a66582 100644 --- a/lib/parse/teachers.ts +++ b/lib/parse/teachers.ts @@ -1,6 +1,10 @@ import { etjanst } from './etjanst' import { Teacher } from '../types' +const abbreviate = (firstname?: string, lastname?: string): string => { + return `${firstname?.substr(0,1)}${lastname?.substr(0,2)}`.toUpperCase() +} + export const teacher = ({ id, sisId, @@ -22,9 +26,5 @@ export const teacher = ({ timeTableAbbreviation: abbreviate(firstname, lastname) }) -const abbreviate = (firstname?: string, lastname?: string): string => { - return `${firstname?.substr(0,1)}${lastname?.substr(0,2)}`.toUpperCase() -} - export const teachers = (data: any): Teacher[] => etjanst(data).map(teacher) From 92ec67e2135164cdc1da992c6ff2a89ede32550a Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 21:40:02 +0200 Subject: [PATCH 5/9] =?UTF-8?q?test:=20=F0=9F=92=8D=20test=20parsing=20tea?= =?UTF-8?q?chers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/parse/__tests__/teachers.test.ts | 68 ++++++++++++++++++++++++++++ lib/parse/teachers.ts | 4 +- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 lib/parse/__tests__/teachers.test.ts diff --git a/lib/parse/__tests__/teachers.test.ts b/lib/parse/__tests__/teachers.test.ts new file mode 100644 index 0000000..9726f4b --- /dev/null +++ b/lib/parse/__tests__/teachers.test.ts @@ -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' + }, + ]) +}) \ No newline at end of file diff --git a/lib/parse/teachers.ts b/lib/parse/teachers.ts index 2a66582..48cea1e 100644 --- a/lib/parse/teachers.ts +++ b/lib/parse/teachers.ts @@ -11,7 +11,7 @@ export const teacher = ({ firstname, lastname, emailaddress, - telWork, + telwork, active, status, }: any): Teacher => ({ @@ -20,7 +20,7 @@ export const teacher = ({ firstname, lastname, email: emailaddress, - phoneWork: telWork, + phoneWork: telwork, active, status, timeTableAbbreviation: abbreviate(firstname, lastname) From a601d0649dc5808b654033b315384f8339fec072 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 21:58:01 +0200 Subject: [PATCH 6/9] =?UTF-8?q?test:=20=F0=9F=92=8D=20test=20parsing=20sch?= =?UTF-8?q?oolContacts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/parse/__tests__/schoolContacts.test.ts | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/parse/__tests__/schoolContacts.test.ts diff --git a/lib/parse/__tests__/schoolContacts.test.ts b/lib/parse/__tests__/schoolContacts.test.ts new file mode 100644 index 0000000..e4dd254 --- /dev/null +++ b/lib/parse/__tests__/schoolContacts.test.ts @@ -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 + } + ]) +}) \ No newline at end of file From 4b90592d0673cea5b92f0bdfda3e26117f822a0e Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 22:35:45 +0200 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Get=20teachers=20from?= =?UTF-8?q?=20all=20education=20levels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index 52ab88a..c9e8b50 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -259,12 +259,22 @@ export class Api extends EventEmitter { public async getTeachers(child: EtjanstChild): Promise { if (this.isFake) return fakeResponse(fake.teachers(child)) - const schoolForm = 'GR' - const url = routes.teachers(child.sdsId, schoolForm) const session = this.getRequestInit() - const response = await this.fetch('teaches', url, session) - const data = await response.json() - return parse.teachers(data) + + const schoolForms = child.status?.split(';') || '' + let teachers: Teacher[] = [] + + for(let i = 0; i< schoolForms.length; i=i+1){ + const url = routes.teachers(child.sdsId, schoolForms[i]) + const response = await this.fetch(`teachers_${schoolForms[i]}`, url, session) + const data = await response.json() + teachers = [ + ...teachers, + ...parse.teachers(data) + ] + } + + return teachers } public async getSchoolContacts(child: EtjanstChild): Promise { From f6e6e1d8490c3e3f137ef442e7c8071bdc7d3b86 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 22:55:05 +0200 Subject: [PATCH 8/9] =?UTF-8?q?style:=20=F0=9F=92=84=20fix=20linting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api.ts | 4 +++- lib/parse/teachers.ts | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index c9e8b50..dcd73cc 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -264,9 +264,11 @@ export class Api extends EventEmitter { const schoolForms = child.status?.split(';') || '' let teachers: Teacher[] = [] - for(let i = 0; i< schoolForms.length; i=i+1){ + 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, diff --git a/lib/parse/teachers.ts b/lib/parse/teachers.ts index 48cea1e..a38c15f 100644 --- a/lib/parse/teachers.ts +++ b/lib/parse/teachers.ts @@ -1,9 +1,8 @@ import { etjanst } from './etjanst' import { Teacher } from '../types' -const abbreviate = (firstname?: string, lastname?: string): string => { - return `${firstname?.substr(0,1)}${lastname?.substr(0,2)}`.toUpperCase() -} +const abbreviate = (firstname?: string, lastname?: string): string => + `${firstname?.substr(0,1)}${lastname?.substr(0,2)}`.toUpperCase() export const teacher = ({ id, From 9a1f9d5074ccd79766d226026a1a3daff36485b0 Mon Sep 17 00:00:00 2001 From: Kajetan Kazimierczak Date: Sun, 3 Oct 2021 23:15:56 +0200 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20for=20undefined?= =?UTF-8?q?=20child=20education=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api.ts b/lib/api.ts index dcd73cc..a6a5999 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -261,7 +261,7 @@ export class Api extends EventEmitter { const session = this.getRequestInit() - const schoolForms = child.status?.split(';') || '' + const schoolForms = (child.status || '').split(';') let teachers: Teacher[] = [] for(let i = 0; i< schoolForms.length; i+=1){