eGovlab / sense4us-simulation

0 stars 0 forks source link

Update the models with this function #16

Open saikyun opened 9 years ago

saikyun commented 9 years ago

This should be used instead of a bunch of if/else-statements when checking the type of an objects attributes, in our case, in the model-files.

function test_object(obj, attributes) { var verified_obj = {}; for (var attr in attributes) { if (typeof obj[attr] === attributes[attr].type.name.toLowerCase() || ((obj[attr] === null || obj[attr] === undefined) && attributes[attr].notNull !== true)) { verified_obj[attr] = obj[attr]; } else { throw new Error(obj + ' doesn\'t have a valid attribute ' + attr + ', it is ' + typeof obj[attr] + ', it should be ' + attributes[attr].type); } } return verified_obj; }