bugfix parameters

This commit is contained in:
Christian Landgren 2020-12-15 03:10:04 +01:00
parent 4fba77ceda
commit 9ece992428
5 changed files with 17 additions and 18 deletions

View File

@ -64,37 +64,37 @@ api.register({
},
getNews: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const childId = c.request.params.childId
const news = await backend.getNews(childId, cookie)
return res.status(200).json(news)
},
getCalendar: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const childId = c.request.params.childId
const calendar = await backend.getCalendar(childId, cookie)
return res.status(200).json(calendar)
},
getNotifications: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const childId = c.request.params.childSdsId
const notifications = await backend.getNotifications(childId, cookie)
return res.status(200).json(notifications)
},
getMenu: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const childId = c.request.params.childId
const menu = await backend.getMenu(childId, cookie)
return res.status(200).json(menu)
},
getSchedule: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const childId = c.request.params.childSdsId
const schedule = await backend.getSchedule(childId, cookie)
return res.status(200).json(schedule)
},
getClassmates: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const childId = c.request.params.childSdsId
const classmates = await backend.getClassmates(childId, cookie)
return res.status(200).json(classmates)
},

View File

@ -10,7 +10,7 @@ const download = (url, cookie) => fetch(url, {headers: {cookie, 'user-agent': 'M
const fetchJson = (url, cookie) => {
return fetch(url, {headers: {cookie}})
.then(res => console.log('fetching', res.url) || res)
//.then(res => console.log('fetching', res.url) || res)
.then(res => res.ok ? res : Promise.reject(res.statusText))
.then(res => res.json())
// convert to camelCase
@ -53,8 +53,8 @@ const getSchedule = (childId, cookie) => fetchJson(urls.schedule(childId, moment
.catch(err => ({err}))
const getClassmates = (childId, cookie) => fetchJson(urls.classmates(childId), cookie)
.then(classmates => classmates.map(({sisId, firstname, lastname, location, guardians, className}) => ({sisId, firstname, lastname, location, guardians, className})))
.catch(err => ({err}))
.then(classmates => classmates.map(({sisId, firstname, lastname, location, guardians = [], className}) => ({sisId, firstname, lastname, location, guardians: guardians.map(({emailhome: email, firstname, lastname, telmobile: mobile, address}) => ({email, firstname, lastname, mobile, address})), className})))
.catch(err => ({err}))
const getChildById = async (childId, cookie) => {
const children = await getChildren()

View File

@ -5,7 +5,7 @@ const urls = {
//loginTarget: `https://login001.stockholm.se/NECSadc/mbid/b64startpage.jsp?startpage=aHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt`,
loginTarget: 'https://login003.stockholm.se/NECSadcmbid/authenticate/SiteMinderAuthADC?TYPE=33554433&REALMOID=06-42f40edd-0c5b-4dbc-b714-1be1e907f2de&GUID=&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=IfNE0iMOtzq2TcxFADHylR6rkmFtwzoxRKh5nRMO9NBqIxHrc38jFyt56FASdxk1&TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvR2V0Q2hpbGRyZW4%3d',
children: `${baseUrl}/vardnadshavare/inloggad2/GetChildren`,
classmates: childId => `${baseurl}/vardnadshavare/inloggad2/contacts/GetStudentsByClass?studentId=${childId}`,
classmates: childId => `${baseUrl}/vardnadshavare/inloggad2/contacts/GetStudentsByClass?studentId=${childId}`,
calendar: childId => `${baseUrl}/vardnadshavare/inloggad2/Calender/GetSchoolCalender?childId=${childId}&rowLimit=50`,
user: `${baseUrl}/vardnadshavare/base/getuserdata`,
news: childId => `${baseUrl}/vardnadshavare/inloggad2/News/GetNewsOverview?childId=${childId}`,

View File

@ -241,7 +241,7 @@ paths:
summary: Lunch Menu
operationId: getMenu
description: Get list of news items for this child
description: Get food menu for the week for this child
security:
- bearerAuth: []
tags:

View File

@ -24,17 +24,16 @@ const test = async () => {
const headers = {authorization: 'Bearer ' + jwt}
const children = await fetch(`http://localhost:9000/children`, {headers}).then(res => res.json())
const data = await Promise.all(children.map(async child => ({
...child,
...await fetch(`http://localhost:9000/children/${child.id}`, {headers}).then(res => res.json())
classmates: await fetch(`http://localhost:9000/children/${child.sdsId}/classmates`, {headers}).then(res => res.json()),
news: await fetch(`http://localhost:9000/children/${child.id}/news`, {headers}).then(res => res.json()),
calendar: await fetch(`http://localhost:9000/children/${child.id}/calendar`, {headers}).then(res => res.json()),
schedule: await fetch(`http://localhost:9000/children/${child.sdsId}/schedule`, {headers}).then(res => res.json()),
menu: await fetch(`http://localhost:9000/children/${child.id}/menu`, {headers}).then(res => res.json()),
notifications: await fetch(`http://localhost:9000/children/${child.sdsId}/notifications`, {headers}).then(res => res.json()),
})))
data.map(async child => ({
...child,
messages: await Promise.all(child.notifications.map((notification) => fetch(notification.url, {headers}).then(res => res.text())))
}))
console.log(JSON.stringify(data, null, 2))
}