-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostprocess.js
49 lines (42 loc) · 1.78 KB
/
postprocess.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
function addReferenceID (data) {
// Checks if correct data came
if (data.hasOwnProperty('TerminationInquiry')) {
try {
// Takes number value from URL "Ref"
data.TerminationInquiry.refId =
data.TerminationInquiry['Ref'].substring(data.TerminationInquiry['Ref'].lastIndexOf('/') + 1);
// Returns data with new property
return data;
} catch (error) {
// Returns original data if something went wrong and logs error
console.log(error);
return data;
}
}
// Returns data otherwise
return data;
}
function formatDate (data) {
// Retrieves object from input data
const dataParsed = JSON.parse(data);
// Checks if correct data came into
if (dataParsed.hasOwnProperty('AddMerchantRequest')) {
// Checks if Merchant object presents in input data
if (dataParsed.AddMerchantRequest.hasOwnProperty('Merchant')) {
// Replaces data-fields to format needed [mm/dd/yyyy]
try {
const dateOpened = new Date(dataParsed.AddMerchantRequest.Merchant['DateOpened']);
const dateClosed = new Date(dataParsed.AddMerchantRequest.Merchant['DateClosed']);
dataParsed.AddMerchantRequest.Merchant['DateOpened'] = dateOpened.toLocaleDateString("en-US");
dataParsed.AddMerchantRequest.Merchant['DateClosed'] = dateClosed.toLocaleDateString("en-US");
// Returns changed data
return JSON.stringify(dataParsed);
} catch (error) {
// Otherwise logs an error and returns untouched data
console.log(error);
return data;
}
}
}
}
module.exports = {addReferenceID, formatDate}