I'm new to node/javascript so my problem is likely trivial, but its causing me trouble no less.
I have the following code. It successfully checks a database for both the Unit
and Owner
values. The problem is that the code following the if statement else if (Owner){
executes as expected, however, AFTER that the program never gets to the return reply(output);
line, which I expect it should.
I think its the way that I am coming back from the Owner.findOne(...
code.
Can anyone see what I'm doing wrong?
exports.sale = {
tags: ['api'],
validate : {
//blah blah blah
},
handler : function(request, reply) {
var output = {
success: true,
operations: [],
epoch: Date.now()
};
Unit.findById(request.payload.deviceNumber, function(err, device) {
if (err) {
//blah blah blah
}
if (device) {
Owner.findOne({OwnerId: device.Owner}, function(err, Owner) {
if (err) {
//blah blah blah
}
else if (Owner){
//make changes to output.operations
}
});
} else {
output.success = false;
}
return reply(output);
});
}
};