tverkettider/endpoint_handlers/suggested.js

34 lines
1 KiB
JavaScript
Raw Normal View History

2023-04-29 13:59:36 +02:00
const SUGGESTED_URL = 'https://fp.trafikverket.se/boka/get-suggested-reservations-by-licence-and-ssn'
async function getSuggestedEndpoint(req, res) {
// Check for the required parameters
if (!req.body || !req.body.licenceId || !req.body.ssn) {
res.status(400).json({ message: 'Missing required parameters' });
return;
}
let ssn = req.body.ssn;
let licenceId = req.body.licenceId;
let response = await fetch(SUGGESTED_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36'
},
body: JSON.stringify({
ssn: ssn,
licenceId: licenceId,
}),
})
if (!response.ok) {
res.status(500).json({ message: 'Something went wrong' });
return;
}
let json = await response.json()
console.log(json)
res.json(json)
}
module.exports = getSuggestedEndpoint;