Browse Source

fetch data from GetInvestmentSummary and store in db

pull/1/head
amol 1 year ago
parent
commit
33fa88fb1b
3 changed files with 113 additions and 96 deletions
  1. +35
    -19
      controller/getAllInvestor.js
  2. +76
    -71
      controller/getInvestmentSumarry.js
  3. +2
    -6
      routes/script.js

+ 35
- 19
controller/getAllInvestor.js View File

@ -32,29 +32,45 @@ const getAllInvstorData = async () => {
const getAllInvstorDataStore = async (body) => {
const records = JSON.parse(body)
let item = records?.data
let storeData = [];
if (item.length) {
for (let i = 0; i < item?.length; i++) {
let data = {};
data.investor_id = item[i].investor_id,
data.name = item[i].name,
data.entity_type = item[i].entity_type,
data.pan = item[i].pan,
data.email = item[i].email,
data.contact_number = item[i].contact_number,
data.ifa_id = item[i].ifa_id,
data.created_at = item[i].created_at,
data.rm_name = item[i].rm_name,
storeData.push(data);
try {
const records = JSON.parse(body)
let item = records?.data
let storeData = [];
if (item.length) {
for (let i = 0; i < item?.length; i++) {
let log = await isInvestorPresent(item[i].investor_id);
if (log == 0) {
let data = {};
data.investor_id = item[i].investor_id,
data.name = item[i].name,
data.entity_type = item[i].entity_type,
data.pan = item[i].pan,
data.email = item[i].email,
data.contact_number = item[i].contact_number,
data.ifa_id = item[i].ifa_id,
data.created_at = item[i].created_at,
data.rm_name = item[i].rm_name,
storeData.push(data);
}
}
console.log("AAAADDDDDDDDDDD_________", storeData.length);
await db.liquiloansInvestors.bulkCreate(storeData);
}
console.log("AAAADDDDDDDDDDD_________", storeData);
await db.liquiloansInvestors.bulkCreate(storeData);
} catch (err) {
console.log(err, "ERROR...........");
}
}
const isInvestorPresent = async (id) => {
try {
let query = `select * from dbo.P2P_Liquiloans_Investors where investor_id= '${id}'`;
return await db.sequelize.query(query, { type: db.sequelize.QueryTypes.SELECT });
} catch (err) {
console.log("isInvestorPresent", err.message)
}
}
module.exports = {


+ 76
- 71
controller/getInvestmentSumarry.js View File

@ -1,7 +1,6 @@
'use strict'
const request = require("request");
const constants = require('../utils/consts');
const db = require('../utils/db_config');
const crypto = require('crypto');
const { getCurrentDateTime } = require("./helper");
@ -11,10 +10,9 @@ function generateHMACSHA256(input, key) {
hmac.update(input, 'utf8'); // Ensure input encoding matches C# (UTF-8)
return hmac.digest('hex');
}
let arrayGetList = ["2509295", "2509", "2820644", "437290"]
function getHashCode(req) {
// console.log(`368907||${getCurrentDateTime()}`, "DKDDODKOODDOK");
const inputString_GetInvestorDashboard = `${req}||${getCurrentDateTime()}`;
const inputString_GetInvestorDashboard = `${req} || ${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
@ -22,92 +20,99 @@ function getHashCode(req) {
}
const fetchAllInvestorId = async (sendId) => {
let data =JSON.parse(sendId)
for (let i = 0; i < data.length; i++) {
await createLiquiloanInvestor(data[i].investor_id)
}
}
const getAllInvestorId = async () => {
let allInvestorId = await db.liquiloansInvestors.findAll({
attributes: ['investor_id']
});
let sendId = JSON.stringify(allInvestorId, null, 2)
fetchAllInvestorId(sendId);
};
const createLiquiloanInvestor = () => {
for (let i = 0; i < arrayGetList.length; i++) {
const createLiquiloanInvestor = (investor_id) => {
var options = {
method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetInvestmentSummary',
headers: {
'Content-Type': 'application/json',
'Cookie': 'AWSALB=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW; AWSALBCORS=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW'
},
body: JSON.stringify({
"investor_id": arrayGetList[i],
"timestamp": getCurrentDateTime(),
"checksum": getHashCode(arrayGetList[i]),
"mid": "M00201"
})
var options = {
method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetInvestmentSummary',
headers: {
'Content-Type': 'application/json',
'Cookie': 'AWSALB=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW; AWSALBCORS=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW'
},
body: JSON.stringify({
"investor_id": investor_id,
"timestamp": getCurrentDateTime(),
"checksum": getHashCode(investor_id),
"mid": "M00201"
})
};
};
request(options, function (error, response) {
if (error) throw new Error(error);
getUrlAndStore(response.body)
});
}
request(options, function (error, response) {
if (error) throw new Error(error);
const data = JSON.parse(response.body);
let callsData = data?.data.past_investments;
if (callsData) {
getUrlAndStore(callsData);
}
});
}
const getUrlAndStore = async (body) => {
const getUrlAndStore = async (callsData) => {
try {
const data = JSON.parse(body)
let callsData = data;
let summary = []
// if (callsData.length) {
//console.log(callsData.data.past_investments.length, "LDPDPLDPLDPLLPDPDLDLPDPLDPL");
for (let i = 0; i < callsData.data.past_investments.length; i++) {
for (let i = 0; i < callsData.length; i++) {
let record = {};
record.transaction_id = callsData.data.past_investments[i].transaction_id,
record.investor_id = callsData.data.past_investments[i].investor_id,
record.scheme_id = callsData.data.past_investments[i].scheme_id,
record.investment_roi = callsData.data.past_investments[i].investment_roi,
record.return_type = callsData.data.past_investments[i].return_type,
record.payout_type = callsData.data.past_investments[i].payout_type,
record.lockin_tenure = callsData.data.past_investments[i].lockin_tenure,
record.lockin_break = callsData.data.past_investments[i].lockin_break,
record.last_withdrawal_at = callsData.data.past_investments[i].last_withdrawal_at,
record.transaction_sub_type = callsData.data.past_investments[i].transaction_sub_type,
record.investment_status = callsData.data.past_investments[i].investment_status,
record.parent_investment_id = callsData.data.past_investments[i].parent_investment_id,
record.master_parent_investment_id = callsData.data.past_investments[i].master_parent_investment_id,
record.quality_name = callsData.data.past_investments[i].quality_name,
record.name = callsData.data.past_investments[i].name,
record.transaction_date = callsData.data.past_investments[i].transaction_date,
record.invested_amount = callsData.data.past_investments[i].invested_amount,
record.scheme_name = callsData.data.past_investments[i].scheme_name,
record.lockin_type = callsData.data.past_investments[i].lockin_type,
record.display_scheme = callsData.data.past_investments[i].display_scheme,
record.scheme_details = callsData.data.past_investments[i].scheme_details,
record.lockin_end_date = callsData.data.past_investments[i].lockin_end_date,
record.redeemed_principal = callsData.data.past_investments[i].redeemed_principal,
record.redeemed_erest = callsData.data.past_investments[i].redeemed_erest,
record.redeemed_erest_with_request = callsData.data.past_investments[i].redeemed_erest_with_request,
record.total_redemption = callsData.data.past_investments[i].total_redemption,
record.net_principal_investment = callsData.data.past_investments[i].net_principal_investment,
record.interest_amount = callsData.data.past_investments[i].interest_amount,
record.accrued_value = callsData.data.past_investments[i].accrued_value,
record.withdrawable_balance = callsData.data.past_investments[i].withdrawable_balance,
record.scheme_closed_date = callsData.data.past_investments[i].scheme_closed_date,
record.request_id = callsData.data.past_investments[i].request_id,
record.source = callsData.data.past_investments[i].source,
record.transaction_id = callsData[i].transaction_id,
record.investor_id = callsData[i].investor_id,
record.scheme_id = callsData[i].scheme_id,
record.investment_roi = callsData[i].investment_roi,
record.return_type = callsData[i].return_type,
record.payout_type = callsData[i].payout_type,
record.lockin_tenure = callsData[i].lockin_tenure,
record.lockin_break = callsData[i].lockin_break,
record.last_withdrawal_at = callsData[i].last_withdrawal_at,
record.transaction_sub_type = callsData[i].transaction_sub_type,
record.investment_status = callsData[i].investment_status,
record.parent_investment_id = callsData[i].parent_investment_id,
record.master_parent_investment_id = callsData[i].master_parent_investment_id,
record.quality_name = callsData[i].quality_name,
record.name = callsData[i].name,
record.transaction_date = callsData[i].transaction_date,
record.invested_amount = callsData[i].invested_amount,
record.scheme_name = callsData[i].scheme_name,
record.lockin_type = callsData[i].lockin_type,
record.display_scheme = callsData[i].display_scheme,
record.scheme_details = callsData[i].scheme_details,
record.lockin_end_date = callsData[i].lockin_end_date,
record.redeemed_principal = callsData[i].redeemed_principal,
record.redeemed_erest = callsData[i].redeemed_erest,
record.redeemed_erest_with_request = callsData[i].redeemed_erest_with_request,
record.total_redemption = callsData[i].total_redemption,
record.net_principal_investment = callsData[i].net_principal_investment,
record.interest_amount = callsData[i].interest_amount,
record.accrued_value = callsData[i].accrued_value,
record.withdrawable_balance = callsData[i].withdrawable_balance,
record.scheme_closed_date = callsData[i].scheme_closed_date,
record.request_id = callsData[i].request_id,
record.source = callsData[i].source,
record.created_at = new Date()
summary.push(record);
}
console.log('calls---->', summary);
await db.investorSummary.bulkCreate(summary);
//}
}
catch (err) {
console.log(err, "KDDODKODKODKODKODKODKO");
// winstonLogger.error('getUrlAndStore() error is : ' + err);
console.log(err, "ERROR.........");
}
}
module.exports = {
createLiquiloanInvestor
getAllInvestorId
}

+ 2
- 6
routes/script.js View File

@ -1,20 +1,16 @@
const express = require('express');
const { route } = require("express/lib/application");
const { createLiquiloanInvestor } = require('../controller/getInvestmentSumarry');
const { getAllInvestorId } = require('../controller/getInvestmentSumarry');
const { fetchInvestorDetails } = require('../controller/getAllInvestor');
const router = express.Router();
router.get("/api/v1", (req, res) => {
// res.send("HELLO I M A NEW COURSE NODE.JS")
createLiquiloanInvestor()
getAllInvestorId()
})
router.get("/api/all_investor", (req, res) => {
fetchInvestorDetails()
})
/* GET users listing. */
module.exports = router;

Loading…
Cancel
Save

Powered by TurnKey Linux.