I've got this little module that returns basic user data required for a web app that's extracted from a large number of columns per row. I was asked to replace the small, column specific select statement I'd prepared with a stored procedure that returns the entire row. This moves column pruning into the server.
I've modified my original function to work as expected with the code below, but it feels like I could be doing better with Array.find((e) => {})
sqlRequest.on('row', function(columns) {
response = {};
const keys = ['id', 'fn', 'ln', 'ctr'];
columns.forEach(function (c) {
let key = String(c.metadata.colName).toLowerCase();
if (keys.find((e) => { return key === e})) {
let value = String(c.value).charAt(0).toUpperCase() + String(c.value).slice(1).toLowerCase();
response[key] = value;
}
});
});