tverkettider/endpoint_handlers/metadata.js
2024-11-05 22:41:56 +01:00

52 lines
No EOL
1.5 KiB
JavaScript
Executable file

const METADATA_ENDPOINT = 'https://fp.trafikverket.se/boka/search-information'
const METADATA_TEMPLATE = {
"bookingSession": {
"socialSecurityNumber": "",
"licenceId": "",
"bookingModeId": 0,
"ignoreDebt": false,
"ignoreBookingHindrance": false,
"examinationTypeId": 0,
"excludeExaminationCategories": [],
"rescheduleTypeId": 0,
"paymentIsActive": false,
"paymentReference": null,
"paymentUrl": null,
"searchedMonths": 0
}
}
async function getMetadataEndpoint(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 body = METADATA_TEMPLATE
body.bookingSession.socialSecurityNumber = ssn
body.bookingSession.licenceId = licenceId
let response = await fetch(METADATA_ENDPOINT, {
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(body),
})
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 = getMetadataEndpoint;