-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
70 lines (63 loc) · 1.73 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var utils = require('./utils');
function getDataList(response, id) {
dataResult = {};
SKIPPED = [];
id.forEach(id => {
data_id = utils.trasnformDataId(id);
if (response.data.hasOwnProperty(data_id)) {
dataResult[data_id] = response.data[data_id];
} else {
SKIPPED.push(data_id);
}
});
if (SKIPPED.length !== 0) {
dataResult.SKIPPED = SKIPPED;
}
return dataResult;
}
function processId(response, id) {
id_type = typeof (id);
switch (id_type) {
case 'string':
data_id = utils.trasnformDataId(id);
return response.data.hasOwnProperty(data_id) ? response.data[data_id] : 'Not Found';
break;
case 'object':
try {
return getDataList(response, id);
} catch (err) {
console.log(err);
return 'Error'
}
break;
default:
return 'Type Error';
break;
}
}
// Find requested data from IFSC details
exports.returnData = function (code, id) {
/**
* code : IFSC code
* id : Key of data requested e.g BRANCH, STATE,etc
*/
return utils.callRazorpay(code).then((response) => {
try {
switch (response.status) {
case 404:
return "Not Found!";
break;
case 200:
if (id == null)
return response.data;
else
return processId(response, id);
break;
default:
return 'Error';
}
} catch (err) {
return null;
}
})
}