// GET - Retrieve login settings
router.route('/login/settings').get((req, res) => {
let settings =[];
pool.connect((err, client, done) => {
client.query('SELECT * FROM public.settings', (err, result) => {
settings = result.rows;
let transformedSettings = settings.map(setting => {
return {
[setting.key]: setting.value
};
});
res.json({
settings: transformedSettings,
});
});
});
});
The API routing code above fetches login settings and returns a JSON object with the following structure:
{
"settings": [
{
"key": "TwoFactorAuth",
"value": "false"
},
{
"key": "sessionTimeout",
"value": "200"
}
]
}
To modify the JSON response to meet the desired format shown below, you can incorporate a loop in the routing code as demonstrated:
{
"settings": [
{
"TwoFactorAuth": "false"
},
{
"sessionTimeout": "200"
}
]
}