'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"); function generateHMACSHA256(input, key) { const hmac = crypto.createHmac('sha256', 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 key = "27E6A91CEE689"; const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key); return hash_GetInvestorDashboard } const createLiquiloanInvestor = () => { for (let i = 0; i < arrayGetList.length; i++) { 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" }) }; request(options, function (error, response) { if (error) throw new Error(error); getUrlAndStore(response.body) }); } } const getUrlAndStore = async (body) => { try { const data = JSON.parse(body) // console.log(data, "111111111111111111111111111111111111111111"); let callsData = data; let calls = []; // if (callsData.length) { console.log(callsData.data.past_investments.length, "LDPDPLDPLDPLLPDPDLDLPDPLDPL"); for (let i = 0; i < callsData.data.past_investments.length; i++) { console.log(); 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 calls.push(record); console.log('calls---->', calls); await db.P2P_Liquiloans_Investors.bulkCreate(calls); // record.sid = callsData[i].Sid; // record.date_created = callsData[i].DateCreated; // record.date_updated = callsData[i].DateUpdated; // record.account_sid = callsData[i].AccountSid; // record.to = callsData[i].To; // record.from = callsData[i].From; // record.phone_number = callsData[i].PhoneNumber; // record.phone_number_sid = callsData[i].PhoneNumberSid; // record.status = callsData[i].Status; // record.start_time = callsData[i].StartTime; // record.end_time = callsData[i].EndTime; // record.duration = callsData[i].Duration; // record.price = callsData[i].Price; // record.direction = callsData[i].Direction; // record.recording_url = callsData[i].RecordingUrl; // record.conversation_duration = callsData[i].Details.ConversationDuration; // record.leg1_status = callsData[i].Details.Leg1Status; // record.leg2_status = callsData[i].Details.Leg2Status; // record.created_at = new Date(); // calls.push(record); // console.log('calls---->', calls.length); // await db.exotelCalls.bulkCreate(calls); } } catch (err) { console.log(err); // winstonLogger.error('getUrlAndStore() error is : ' + err); } } module.exports = { createLiquiloanInvestor }