diff --git a/apps/api-test-app/src/main.js b/apps/api-test-app/src/main.js index 6c1123d5..ca61f19d 100644 --- a/apps/api-test-app/src/main.js +++ b/apps/api-test-app/src/main.js @@ -24,7 +24,7 @@ const init = isAdmentum ? initAdmentum : initSkolplattformen process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' const cookieJar = new CookieJar() -let bankIdUsed = false +let bankIdUsed = true const recordFolder = `${__dirname}/record` async function run() { @@ -45,12 +45,12 @@ async function run() { console.log('children') const children = await api.getChildren() console.log(children) - /* + console.log('calendar') const calendar = await api.getCalendar(children[0]) console.log(calendar) - console.log('classmates') + /*console.log('classmates') const classmates = await api.getClassmates(children[0]) console.log(classmates) diff --git a/libs/api-admentum/lib/apiAdmentum.ts b/libs/api-admentum/lib/apiAdmentum.ts index 1104cc33..9fc7a163 100644 --- a/libs/api-admentum/lib/apiAdmentum.ts +++ b/libs/api-admentum/lib/apiAdmentum.ts @@ -144,7 +144,7 @@ export class ApiAdmentum extends EventEmitter implements Api { async getUser(): Promise { console.log('fetching user') - const userId = '437302' + const userId = '437236' const currentUserResponse = await this.fetch( 'current-user', apiUrls.user(userId) @@ -162,11 +162,10 @@ export class ApiAdmentum extends EventEmitter implements Api { if (!this.isLoggedIn) { throw new Error('Not logged in...') } - console.log("get no children") - return [] - const testUserId = '436838' + console.log("get children") + const testUserId = '437236' const fetchUrl = apiUrls.user(testUserId) - console.log('v3.3 fetching children for user id', testUserId, 'from', fetchUrl) + console.log('v3.4 fetching children for user id', testUserId, 'from', fetchUrl) const currentUserResponse = await this.fetch('current-user', fetchUrl, { method: 'GET', headers: { @@ -174,7 +173,6 @@ export class ApiAdmentum extends EventEmitter implements Api { }, }) - if (currentUserResponse.status !== 200) { console.error('Error headers', currentUserResponse.headers) throw new Error('Could not fetch children. Response code: ' + currentUserResponse.status) @@ -191,7 +189,15 @@ export class ApiAdmentum extends EventEmitter implements Api { } async getCalendar(child: EtjanstChild): Promise { - return Promise.resolve([]) + if (!this.isLoggedIn) { + throw new Error('Not logged in...') + } + + const [year, week] = new DateTime().toISOWeekDate().split('-') + const isoWeek = week.replace('W','') + const fetchUrl = apiUrls.schedule(year, isoWeek) + const calendarResponse = await this.fetch('get-calendar', fetchUrl) + return calendarResponse.map(parseCalendarItem) } // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/libs/api-admentum/lib/parse/parsers.ts b/libs/api-admentum/lib/parse/parsers.ts index 0ca46260..83c22e5f 100644 --- a/libs/api-admentum/lib/parse/parsers.ts +++ b/libs/api-admentum/lib/parse/parsers.ts @@ -46,13 +46,113 @@ export function extractAuthGbgLoginRequestBody(signatureResponseText: string) { return authGbgLoginBody } -export const parseCalendarItem = (x: html.HTMLElement): { id: number; title: string; startDate: string; endDate: string } => { - const info = Array.from(x.querySelectorAll('a')) - // TODO: the identifier is realy on this format: '\d+:\d+' currently we only take the first part so Id will clash between items - const id = info[0].getAttribute("onClick")?.replace(new RegExp("return viewEvent\\('(\\d+).+"), "$1") || NaN - const day = info[1].textContent - const timeSpan = info[2].textContent - const [startTime, endTime] = timeSpan.replace(".", ":").split("-") +export const parseCalendarItem = (jsonRow: any): any => { + + return {} + +} - return { id: +id, title: info[0].textContent, startDate: `${day} ${startTime}`, endDate: `${day} ${endTime}` } -} \ No newline at end of file +/* +{ + "week_number": 40, + "days": [ + { + "date": "2023-10-02", + "formated_date": "2 okt", + "name": "MÃ¥ndag", + "lessons": [ + { + "title": "BI", + "tooltip_title": "Biologi", + "subject_name": "Biologi", + "subject_code": "BI", + "teachers": "FCa", + "intervals": 3.0, + "overlaps": 1, + "start_pos": 4.0, + "color": "#e97f23", + "time": "10:00 - 11:30", + "room": "", + "groups": "6 A BI", + "tooltip": "10:00 - 11:30
6 A BI", + "lesson_id": 14998270, + "lesson_info": "", + "lesson_groups": "6 A BI", + "body": "BI", + "information": null + } + ], + "breaks": [], + "events": [] + }, + { + "date": "2023-10-03", + "formated_date": "3 okt", + "name": "Tisdag", + "lessons": [], + "breaks": [], + "events": [] + }, + { + "date": "2023-10-04", + "formated_date": "4 okt", + "name": "Onsdag", + "lessons": [], + "breaks": [], + "events": [] + }, + { + "date": "2023-10-05", + "formated_date": "5 okt", + "name": "Torsdag", + "lessons": [], + "breaks": [], + "events": [] + }, + { + "date": "2023-10-06", + "formated_date": "6 okt", + "name": "Fredag", + "lessons": [], + "breaks": [], + "events": [] + } + ], + "query": "week=40&user_id=437235", + "time_range": [ + "8:00", + "8:30", + "9:00", + "9:30", + "10:00", + "10:30", + "11:00", + "11:30", + "12:00", + "12:30", + "13:00", + "13:30", + "14:00", + "14:30", + "15:00", + "15:30", + "16:00", + "16:30", + "17:00" + ], + "section_count": 18, + "breaks": [], + "schedule_event_instances": [], + "schedule": { + "id": 4385, + "start_week": 31, + "start_year": 2023, + "end_week": 22, + "end_year": 2024 + }, + "next_week": 41, + "prev_week": 39, + "weeks_amount": 52, + "break_week": 27 +} +*/ \ No newline at end of file diff --git a/libs/api-admentum/lib/routes.ts b/libs/api-admentum/lib/routes.ts index 637982e6..7b957209 100644 --- a/libs/api-admentum/lib/routes.ts +++ b/libs/api-admentum/lib/routes.ts @@ -33,7 +33,8 @@ export const apiUrls = { baseUrl + 'schedule_group_teacher_enrollments', schedule_groups: baseUrl + 'schedule_groups', schedules: baseUrl + 'schedules', - school_enrollments: baseUrl + 'school_enrollments', + schedule: (year: string, week: string) => baseUrl + `schedule?week=${week}&year=${year}`, + school_enrollments: `${baseUrl}school_enrollments`, school_years: baseUrl + 'school_years', schools: baseUrl + 'schools', sickness: baseUrl + 'sickness', diff --git a/libs/api-admentum/package.json b/libs/api-admentum/package.json index ae9bdc50..22151be9 100644 --- a/libs/api-admentum/package.json +++ b/libs/api-admentum/package.json @@ -7,7 +7,7 @@ "dist/**/*" ], "repository": "git@github.com:kolplattformen/skolplattformen.git", - "author": "Erik Eng ", + "author": "Christian Landgren, William Ryder ", "license": "Apache-2.0", "private": false, "scripts": {