-
Notifications
You must be signed in to change notification settings - Fork 3
/
fieldsLoader.js
50 lines (46 loc) · 1.51 KB
/
fieldsLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module.exports = function(reusableFile){
var reusableRequiredFields = require(reusableFile);
/*
Returns the corresponding field object from the reusableRequiredFields variable
@name: the name of the field
@options: optionally pass an options object. All keys of this object will be used to overwrite the default values
of the the corresponding keys of the original field definition.
Example:
getField('orgId')
Returns:
{
key:'orgId',
type:'int',
humanReadable: 'organization id',
description:'The Organization from which data is requested',
mandatory:true
}
getField('orgId', {mandatory:false});
Returns:
{
key:'orgId',
type:'int',
humanReadable: 'organization id',
description:'The Organization from which data is requested',
mandatory:false
}
*/
this.getField = function(name, options){
if(!reusableRequiredFields[name]){
console.log('The requested field ' + name + ' does not exist on the reusableRequiredFields object');
return {
key:'invalid_key'
};
} else {
var toReturn = JSON.parse(JSON.stringify(reusableRequiredFields[name]));
if(!!options){
var keys = Object.keys(options);
for(var i=0; i<keys.length; i++){
var key = keys[i];
toReturn[key] = options[key];
}
}
return toReturn;
}
}
}