-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_esaf_msisdn_extract.js
94 lines (81 loc) · 3.26 KB
/
api_esaf_msisdn_extract.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const axios = require('axios');
const RequestTypes = require('./constants/request_type')
const Util = require('./util/util');
const Api = require('./api');
const Url = require('./constants/backend_url');
const { socket_init, socketSyncInit } = require('./socket_client/service');
function getEsafBody(body,searchValue){
const currUnixTime = Math.floor(new Date().getTime() / 1000) - Util.daysInSeconds(1);
let dubBody = {
"userId": body.userId || null,
"caseId": body.caseId || null,
"agencyId": body.agencyId || null,
"searchMode": body.searchMode || null,
"discoveryId": body.discoveryId || null,
"unifiedViewerId": body.unifiedViewerId || null,
"requestType": RequestTypes.RequestTypes.ESAF,
"searchCriteria": 4,
"searchValue": searchValue,
"startDate": currUnixTime - Util.daysInSeconds(7),
"endDate": currUnixTime,
"channels": [...body.channels]
}
return dubBody
}
function getDrivingLicenseBody(body,searchValue){
let dubBody = {
"userId": body.userId || null,
"caseId": body.caseId || null,
"agencyId": body.agencyId || null,
"searchMode": body.searchMode || null,
"discoveryId": body.discoveryId || null,
"unifiedViewerId": body.unifiedViewerId || null,
"parameterType": "mobileNumber",
"parameterValue": searchValue,
"channels": body.channels
}
return dubBody
}
async function axiosEsafNumCall(nids,body) {
return await new Promise(async function (accept, reject) {
let count = 0
let url = Url.esafURL
const ruleEngineChannel = `${body.channels[0]}_${Util.create_UUID()}_NumExtraction`
let socket = await socketSyncInit(ruleEngineChannel);
console.log("Socket Init Complete for Number Extraction fact")
let dubBody = JSON.parse(JSON.stringify(body))
dubBody.channels.push(ruleEngineChannel)
socket.on(ruleEngineChannel, res => {
count++;
let result = JSON.parse(JSON.parse(res));
let uniquePartyA = new Set();
try {
result.data.responseRecord.forEach(esaf => {
uniquePartyA.add(esaf.phone)
});
console.log("Unique phone:", uniquePartyA, "Operator: ", result.data.operator)
uniquePartyA.forEach((msisdn) => {
let drivingLicenseBody = getDrivingLicenseBody(body,msisdn)
Api.axiosCall(Url.drivingLicenseURL,drivingLicenseBody)
})
} catch (TypeError) {
console.log("DATA NOT FOUND ERROR")
}
if (count == 12) {
console.log("Number Extraction Complete")
accept(socket);
}
});
nids.forEach(nid => {
let esafBody = getEsafBody(dubBody,nid)
console.log("Posting To Esaf for Number Extraction with body:", esafBody, "URL:", url)
axios.post(url, esafBody);
});
}).then((socket) => {socket.destroy()}).catch((error) => {
console.log("error while extracting esaf from nids with body: " + body);
console.log("Error: " + error);
});
}
module.exports = {
axiosEsafNumCall
};