1
|
|
|
|
2
|
|
|
module.exports = { |
3
|
|
|
buildAuthenticationHeader: function (inAuthenticationArray) { |
4
|
|
|
var aReturn; |
5
|
|
|
switch (inAuthenticationArray.type) { |
6
|
|
|
case 'Addin': |
7
|
|
|
aReturn = inAuthenticationArray.credentials_Addin; |
8
|
|
|
break; |
9
|
|
|
case 'SAML': |
10
|
|
|
aReturn = inAuthenticationArray.credentials_SAML; |
11
|
|
|
break; |
12
|
|
|
default: |
13
|
|
|
aReturn = false; |
14
|
|
|
break; |
15
|
|
|
} |
16
|
|
|
return aReturn; |
17
|
|
|
}, |
18
|
|
|
buildCurrentListAttributeValues: function (inObjectListsConfiguredAttributes, inCurrentList) { |
19
|
|
|
var crtListAttributes = []; |
20
|
|
|
Object.keys(inObjectListsConfiguredAttributes).map(function (itemList) { |
21
|
|
|
if (itemList.substring(0, 4) === 'Date') { |
22
|
|
|
if (inCurrentList[inObjectListsConfiguredAttributes[itemList]] === null) { |
23
|
|
|
crtListAttributes[itemList] = 'null'; |
24
|
|
|
} else { |
25
|
|
|
crtListAttributes[itemList] = inCurrentList[inObjectListsConfiguredAttributes[itemList]].replace('T', ' ').replace('Z', ''); |
26
|
|
|
} |
27
|
|
|
} else { |
28
|
|
|
crtListAttributes[itemList] = inCurrentList[inObjectListsConfiguredAttributes[itemList]]; |
29
|
|
|
} |
30
|
|
|
}); |
31
|
|
|
return crtListAttributes; |
32
|
|
|
}, |
33
|
|
|
buildCurrentItemValues: function (fieldAttributes, item) { |
34
|
|
|
var crtRecord = []; |
35
|
|
|
var counterF = 0; |
36
|
|
|
Object.keys(fieldAttributes).map(function (itemF) { |
37
|
|
|
switch (fieldAttributes[itemF]['Type']) { |
38
|
|
|
case 'DateTime': |
39
|
|
|
if (item[fieldAttributes[itemF]['Technical Name']] === null) { |
40
|
|
|
crtRecord[counterF] = 'null'; |
41
|
|
|
} else { |
42
|
|
|
crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']].replace('T', ' ').replace('Z', ''); |
43
|
|
|
} |
44
|
|
|
break; |
45
|
|
|
case 'Lookup': |
46
|
|
|
case 'User': |
47
|
|
|
crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name'] + 'Id']; |
48
|
|
|
break; |
49
|
|
|
default: |
50
|
|
|
crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']]; |
51
|
|
|
break; |
52
|
|
|
} |
53
|
|
|
counterF++; |
54
|
|
|
}); |
55
|
|
|
return crtRecord; |
56
|
|
|
}, |
57
|
|
|
buildCurrentRecordValues: function (inFieldsArray, crtRecordValues) { |
58
|
|
|
var crtRecordGM = []; |
59
|
|
|
var counterGM = 0; |
60
|
|
|
Object.keys(inFieldsArray).map(function (itemGM) { |
61
|
|
|
if (inFieldsArray[itemGM] === 'HtmlSchemaXml') { |
62
|
|
|
crtRecordGM[counterGM] = JSON.stringify(crtRecordValues[inFieldsArray[itemGM]]); |
63
|
|
|
} else { |
64
|
|
|
crtRecordGM[counterGM] = crtRecordValues[inFieldsArray[itemGM]]; |
65
|
|
|
} |
66
|
|
|
counterGM++; |
67
|
|
|
}); |
68
|
|
|
return crtRecordGM; |
69
|
|
|
}, |
70
|
|
|
buildRequestQuery: function (targetSharePointURL, arStandardLists, crtListName, queryType, inData) { |
71
|
|
|
var queryPrefix = ''; |
72
|
|
|
if (Object.keys(arStandardLists).indexOf(queryType) > -1) { |
73
|
|
|
queryPrefix = '_api/Web/' + arStandardLists[queryType]['APItrunk'] |
74
|
|
|
+ '/' + arStandardLists[queryType]['APIfunction'] + '(\'' |
75
|
|
|
+ crtListName + '\')/' + arStandardLists[queryType]['APIelement']; |
76
|
|
|
} else { |
77
|
|
|
queryPrefix = '_api/Web/' + queryType; |
78
|
|
|
} |
79
|
|
|
var headerOptions = inData.headers; |
80
|
|
|
headerOptions['Accept'] = 'application/json;odata=verbose'; |
81
|
|
|
return { |
82
|
|
|
url: targetSharePointURL + queryPrefix, |
83
|
|
|
headers: headerOptions, |
84
|
|
|
json: true |
85
|
|
|
}; |
86
|
|
|
}, |
87
|
|
|
decideBlackListWhiteList: function (inDecisionValue, inEvaluatedValueForBlackList, inBlackListArray, inEvaluatedValueForWhiteList, inWhiteListArray, inValueToEvaluate) { |
88
|
|
|
var bolReturn = false; |
89
|
|
|
if ((inDecisionValue === inEvaluatedValueForBlackList) && (inBlackListArray.indexOf(inValueToEvaluate) === -1)) { |
90
|
|
|
bolReturn = true; |
91
|
|
|
} |
92
|
|
|
if ((inDecisionValue === inEvaluatedValueForWhiteList) && (inWhiteListArray.indexOf(inValueToEvaluate) > -1)) { |
93
|
|
|
bolReturn = true; |
94
|
|
|
} |
95
|
|
|
return bolReturn; |
96
|
|
|
}, |
97
|
|
|
internalQueryStructureArray: function (maxRecords) { |
98
|
|
|
return { |
99
|
|
|
'Fields': {'APItrunk': 'Lists', 'APIfunction': 'GetByTitle', 'APIelement': 'Fields'}, |
100
|
|
|
'GroupMembers': {'APItrunk': 'SiteGroups', 'APIfunction': 'GetById', 'APIelement': 'Users'}, |
101
|
|
|
'Items': {'APItrunk': 'Lists', 'APIfunction': 'GetByTitle', 'APIelement': 'Items' + '?$top=' + maxRecords}, |
102
|
|
|
'Views': {'APItrunk': 'Lists', 'APIfunction': 'GetByTitle', 'APIelement': 'Views'} |
103
|
|
|
}; |
104
|
|
|
} |
105
|
|
|
}; |
106
|
|
|
|