This is the **** I have to deal with on the day job. I have been BEGGING for node things to work on for over a year. Huge company so I never know what everyone is working on. But presumably my boss could play some kind of role in finding things for me to do which match the reason he hired me. Crazy idea I know.
So anyway one of the few things I do get to do is review someone else's node app every now and then. This app I've already reviewed once, found a bunch of errors, which he fixed. Fast forward a few months, he sent me a link to review again. I found one bug, but otherwise it looked good. He mentioned that he had made some changes. We get on the meeting yesterday and it's totally different code. He expected me to review it over web-connect as he scrolled by. Um no.
*So today he sends me the PR of the new code. This is just a sample:
Code:
metadataCall: function(app, logger) {
const unirest=require("unirest");
//variable to store the obfuscated values
var i=0, host, metadataObj = {
metadataSuccess: null,
obfuscatedYesInMetadata : []
};
(function processMetadataCall() {
switch (process.env.NODE_ENV) {
case 'production':
host="www.X.com";
break;
case 'finalstage':
host="finalstage.X.com";
break;
case 'test':
host="tst13.stage.X.com";
break;
case 'development':
host="tst13.stage.X.com"; //localhost
break;
default:
host="tst13.stage.X.com";
}
const serviceOptions = {
host : host, //process.env.NODE_ENV = 'production' ? "http://www.X.com":"http://tst13.stage.X.com",
path : "/apis/personalization/goldeneye/internal/uuidprofilemetadata/attributemetadata",
// headers: {},
method: "GET"
};
unirest.get("http://"+serviceOptions.host+serviceOptions.path).end(function(response){
if (response.status === 200) {
if (response.body !== null && response.body !== undefined) {
metadataObj.metadataSuccess = true;
processSuccessfulResponse(response.body);
} else {
logger.log('error', "Error receiving data from the Metadata service call");
metadataObj.metadataSuccess = false;
}
} else {
metadataObj.metadataSuccess = false;
logger.log('error', "attributemetadata call failed with "+response.status);
}
});
var processSuccessfulResponse = function(data) {
// var responseData = JSON.parse(data);
var responseData = data;
if (responseData !== null && responseData !== undefined) {
for (var key in responseData) {
if (responseData.hasOwnProperty(key)) {
var value = responseData[key];
for (var key1 in value) {
if (key1 === 'goldenEyeAttributeMetadata' && typeof value[key1] === "object") {
var value2 = value[key1];
for (var key2 in value2) {
if (key2 === "obfuscatedValue" && value2[key2] === true) {
metadataObj.obfuscatedYesInMetadata[i] = value['goldenEyeAttributeName'];
i++;
}
}
}
}
} else {
logger.log('error', "Error with the response received from the Metadata service call");
}
}
} else {
logger.log('error', "Error parsing the response received from the Metadata service call");
}
};
})();
return metadataObj;
Holy hell. He doesn't know how to access properties in a JS object w/o looping over them. The switch statement couldn't be more unnecessary. I don't think he has any idea why he's using self-executing functions. But worst of all - his async get method is NEVER GOING TO DO ANYTHING. Arghhh.
Meanwhile I am begging for scraps of node work. This code was so bad I actually mentioned it to his boss, who was on the meeting yesterday. Also because I was ticked about the code bait and switch. His response was basically: yeah we can't find good node people, and only contractors are allowed to develop. Totally FUBAR.