-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_imei_cdr.js
51 lines (46 loc) · 1.55 KB
/
api_imei_cdr.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
const axios = require('axios');
const e = require('express');
const imeiRule = require("./rules/imei_rule");
/**
*
* @param {string} url
* @param {*} body
* @param {socket} socket
* @returns
*/
async function axiosIMEICDRCall(url, body, socket) {
console.log("Posting with body:", body, "URL:", url)
let result = new Promise(function (accept, reject) {
let count = 0
socket.on(body.channels[body.channels.length - 1], res => {
count++;
let result = JSON.parse(JSON.parse(res));
let uniquePartyA = new Set();
try {
result.data.responseRecord.forEach(call => {
uniquePartyA.add(call.partyA)
});
console.log("Unique Party A:", uniquePartyA, "Operator: ", result.data.operator)
uniquePartyA.forEach((msisdn) => {
let dubBody = {
"searchValue": msisdn,
"startDate": body.startDate,
"endDate": body.endDate,
"channels": body.channels.slice(0,body.channels.length - 1)
};
imeiRule.imeiRuleForDiscovery(dubBody);
})
} catch (TypeError) {
console.log("DATA NOT FOUND FOR IMEI")
}
if (count == 4) {
accept(socket);
}
});
}).then((socket)=>{socket.destroy()});
axios.post(url, body);
return await result;
}
module.exports = {
axiosIMEICDRCall
};