|
|
@ -1,10 +1,13 @@ |
|
|
|
'use strict' |
|
|
|
|
|
|
|
const request = require("request"); |
|
|
|
const db = require('../utils/db_config'); |
|
|
|
const db = require('../../utils/db_config'); |
|
|
|
const crypto = require('crypto'); |
|
|
|
const {getReqAndInvId} = require('./getTransactionById') |
|
|
|
const { getCurrentDateTime } = require("./helper"); |
|
|
|
const { getReqAndInvId } = require('../getTransactionById') |
|
|
|
const { getCurrentDateTime } = require("../helper"); |
|
|
|
const { HASH_KEY } = require("../../utils/consts"); |
|
|
|
const { getInvSummaryIdQuery } = require("./query"); |
|
|
|
const { errorLogStatus } = require("../Errorlog"); |
|
|
|
|
|
|
|
function generateHMACSHA256(input, key) { |
|
|
|
const hmac = crypto.createHmac('sha256', key); |
|
|
@ -14,7 +17,7 @@ function generateHMACSHA256(input, key) { |
|
|
|
|
|
|
|
function getHashCode(req) { |
|
|
|
const inputString_GetInvestorDashboard = `${req}||${getCurrentDateTime()}`; |
|
|
|
const key = "27E6A91CEE689"; |
|
|
|
const key = HASH_KEY; |
|
|
|
|
|
|
|
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key); |
|
|
|
return hash_GetInvestorDashboard |
|
|
@ -24,7 +27,7 @@ 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,i) |
|
|
|
await createLiquiloanInvestor(data[i].investor_id, i) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -37,7 +40,7 @@ const getAllInvestorId = async () => { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const createLiquiloanInvestor = (investor_id,index) => { |
|
|
|
const createLiquiloanInvestor = (investor_id, index) => { |
|
|
|
|
|
|
|
var options = { |
|
|
|
method: 'POST', |
|
|
@ -53,7 +56,7 @@ const createLiquiloanInvestor = (investor_id,index) => { |
|
|
|
}) |
|
|
|
}; |
|
|
|
|
|
|
|
request(options, function (error, response,body) { |
|
|
|
request(options, function (error, response, body) { |
|
|
|
if (error) throw new Error(error); |
|
|
|
const data = JSON.parse(body); |
|
|
|
let pastData = data?.data.past_investments; |
|
|
@ -64,17 +67,15 @@ const createLiquiloanInvestor = (investor_id,index) => { |
|
|
|
if (currentData) { |
|
|
|
getUrlAndStore(currentData); |
|
|
|
} |
|
|
|
console.log(index,"investor_id-->",investor_id,"currentData-->",currentData.length,"pastData-->",pastData.length) |
|
|
|
console.log(index, "investor_id-->", investor_id, "currentData-->", currentData.length, "pastData-->", pastData.length) |
|
|
|
}); |
|
|
|
} |
|
|
|
const getUrlAndStore = async (callsData) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
let summary = [] |
|
|
|
for (let i = 0; i < callsData.length; i++) { |
|
|
|
let checkTrnId = await isRequestIdPresent(callsData[i].request_id); |
|
|
|
let checkTrnId = await getInvSummaryIdQuery(callsData[i].request_id); |
|
|
|
if (checkTrnId == 0) { |
|
|
|
let record = {}; |
|
|
|
record.transaction_id = callsData[i].transaction_id, |
|
|
@ -110,32 +111,40 @@ const getUrlAndStore = async (callsData) => { |
|
|
|
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() |
|
|
|
record.last_updatedAt = new Date() |
|
|
|
record.created_at = new Date().toString() |
|
|
|
record.last_updatedAt = new Date().toString() |
|
|
|
|
|
|
|
summary.push(record); |
|
|
|
} else { |
|
|
|
let record = { |
|
|
|
...callsData[i], |
|
|
|
last_updatedAt: new Date().toString() |
|
|
|
} |
|
|
|
await db.transactionById.update(record, { |
|
|
|
where: { |
|
|
|
transaction_id: record.transaction_id |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if(summary.length){ |
|
|
|
if (summary.length) { |
|
|
|
await db.investorSummary.bulkCreate(summary); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
catch (err) { |
|
|
|
console.log(err, "ERROR........."); |
|
|
|
errorLogStatus(err, "nodeJs_liquiloan_getUrlAndStore") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// check is transaction id is present
|
|
|
|
const isRequestIdPresent = async (id) => { |
|
|
|
try { |
|
|
|
let query = `select * from dbo.P2P_Liquiloans_Inv_Summarys where request_id= '${id}'`; |
|
|
|
return await db.sequelize.query(query, { type: db.sequelize.QueryTypes.SELECT }); |
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
console.log("isIransactionId", err.message) |
|
|
|
} |
|
|
|
} |
|
|
|
// const isRequestIdPresent = async (id) => {
|
|
|
|
// try {
|
|
|
|
// getInvSummaryIdQuery(id)
|
|
|
|
// } catch (err) {
|
|
|
|
// errorLogStatus(err, "nodeJs_liquiloan_isRequestIdPresent")
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
getAllInvestorId |