Browse Source

Store data in db from getTrnById

pull/1/head
amol 1 year ago
parent
commit
ae7064283e
8 changed files with 287 additions and 57 deletions
  1. +26
    -6
      controller/getAllInvestor.js
  2. +74
    -49
      controller/getInvestmentSumarry.js
  3. +137
    -0
      controller/getTransactionById.js
  4. +1
    -0
      model/investorSummary.js
  5. +1
    -0
      model/liquiloansInvestors.js
  6. +38
    -0
      model/transactionById.js
  7. +9
    -2
      routes/script.js
  8. +1
    -0
      utils/db_config.js

+ 26
- 6
controller/getAllInvestor.js View File

@ -1,7 +1,26 @@
'use strict' 'use strict'
const request = require('request'); const request = require('request');
const db = require('../utils/db_config')
const db = require('../utils/db_config');
const { getCurrentDateTime } = require("./helper");
const {getAllInvestorId} = require('./getInvestmentSumarry')
const crypto = require('crypto');
function generateHMACSHA256(input, key) {
const hmac = crypto.createHmac('sha256', key);
hmac.update(input, 'utf8');
return hmac.digest('hex');
}
function getHashCode(req) {
const inputString_GetInvestorDashboard = `||${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
return hash_GetInvestorDashboard
}
const fetchInvestorDetails = ((req, res) => { const fetchInvestorDetails = ((req, res) => {
getAllInvstorData(); getAllInvstorData();
@ -9,7 +28,7 @@ const fetchInvestorDetails = ((req, res) => {
}) })
const getAllInvstorData = async () => { const getAllInvstorData = async () => {
var options = { var options = {
method: 'POST', method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetAllInvestors', url: 'https://supply-integration.liquiloans.com/api/v2/GetAllInvestors',
@ -18,12 +37,11 @@ const getAllInvstorData = async () => {
}, },
body: JSON.stringify({ body: JSON.stringify({
mid: "M00201", mid: "M00201",
checksum: "e7d0ab9fb1c79796a6ae6fd22600e22129e9fef1bfe9577717f9953d0e9064ff",
timestamp: "2023-12-11 14:57:38",
checksum: getHashCode(),
timestamp: getCurrentDateTime(),
filter_on: "", filter_on: "",
filter_data: [] filter_data: []
}) })
}; };
request(options, function (error, response) { request(options, function (error, response) {
if (error) throw new Error(error); if (error) throw new Error(error);
@ -33,6 +51,7 @@ const getAllInvstorData = async () => {
const getAllInvstorDataStore = async (body) => { const getAllInvstorDataStore = async (body) => {
try { try {
const records = JSON.parse(body) const records = JSON.parse(body)
let item = records?.data let item = records?.data
@ -51,13 +70,14 @@ const getAllInvstorDataStore = async (body) => {
data.ifa_id = item[i].ifa_id, data.ifa_id = item[i].ifa_id,
data.created_at = item[i].created_at, data.created_at = item[i].created_at,
data.rm_name = item[i].rm_name, data.rm_name = item[i].rm_name,
data.last_updatedAt = new Date
storeData.push(data); storeData.push(data);
} }
} }
console.log("AAAADDDDDDDDDDD_________", storeData.length);
await db.liquiloansInvestors.bulkCreate(storeData); await db.liquiloansInvestors.bulkCreate(storeData);
} }
} catch (err) { } catch (err) {
console.log(err, "ERROR..........."); console.log(err, "ERROR...........");
} }


+ 74
- 49
controller/getInvestmentSumarry.js View File

@ -3,6 +3,7 @@
const request = require("request"); const request = require("request");
const db = require('../utils/db_config'); const db = require('../utils/db_config');
const crypto = require('crypto'); const crypto = require('crypto');
const {getReqAndInvId} = require('./getTransactionById')
const { getCurrentDateTime } = require("./helper"); const { getCurrentDateTime } = require("./helper");
function generateHMACSHA256(input, key) { function generateHMACSHA256(input, key) {
@ -12,7 +13,7 @@ function generateHMACSHA256(input, key) {
} }
function getHashCode(req) { function getHashCode(req) {
const inputString_GetInvestorDashboard = `${req} || ${getCurrentDateTime()}`;
const inputString_GetInvestorDashboard = `${req}||${getCurrentDateTime()}`;
const key = "27E6A91CEE689"; const key = "27E6A91CEE689";
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key); const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
@ -21,9 +22,9 @@ function getHashCode(req) {
} }
const fetchAllInvestorId = async (sendId) => { const fetchAllInvestorId = async (sendId) => {
let data =JSON.parse(sendId)
let data = JSON.parse(sendId)
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
await createLiquiloanInvestor(data[i].investor_id)
await createLiquiloanInvestor(data[i].investor_id,i)
} }
} }
@ -36,14 +37,13 @@ const getAllInvestorId = async () => {
}; };
const createLiquiloanInvestor = (investor_id) => {
const createLiquiloanInvestor = (investor_id,index) => {
var options = { var options = {
method: 'POST', method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetInvestmentSummary', url: 'https://supply-integration.liquiloans.com/api/v2/GetInvestmentSummary',
headers: { headers: {
'Content-Type': 'application/json',
'Cookie': 'AWSALB=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW; AWSALBCORS=9yK+sr19KPz9dgL+OcWl2hZ9MOhLlvF9PtNolmRnkviHh01CvjlIWH44NtfjIziyJFwnhrn3+JNhztFLJis+Ijq971nXr5QQVJBxId1uvjZyqKSl/6oFuidGkloW'
'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
"investor_id": investor_id, "investor_id": investor_id,
@ -53,65 +53,90 @@ const createLiquiloanInvestor = (investor_id) => {
}) })
}; };
request(options, function (error, response) {
request(options, function (error, response,body) {
if (error) throw new Error(error); if (error) throw new Error(error);
const data = JSON.parse(response.body);
let callsData = data?.data.past_investments;
if (callsData) {
getUrlAndStore(callsData);
const data = JSON.parse(body);
let pastData = data?.data.past_investments;
if (pastData) {
getUrlAndStore(pastData);
} }
let currentData = data?.data.current_investments;
if (currentData) {
getUrlAndStore(currentData);
}
console.log(index,"investor_id-->",investor_id,"currentData-->",currentData.length,"pastData-->",pastData.length)
}); });
} }
const getUrlAndStore = async (callsData) => { const getUrlAndStore = async (callsData) => {
try { try {
let summary = [] let summary = []
for (let i = 0; i < callsData.length; i++) { for (let i = 0; i < callsData.length; i++) {
let record = {};
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);
let checkTrnId = await isRequestIdPresent(callsData[i].request_id);
if (checkTrnId == 0) {
let record = {};
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()
record.last_updatedAt = new Date()
summary.push(record);
}
}
if(summary.length){
await db.investorSummary.bulkCreate(summary);
} }
await db.investorSummary.bulkCreate(summary);
} }
catch (err) { catch (err) {
console.log(err, "ERROR........."); console.log(err, "ERROR.........");
} }
} }
// 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)
}
}
module.exports = { module.exports = {
getAllInvestorId getAllInvestorId
} }


+ 137
- 0
controller/getTransactionById.js View File

@ -0,0 +1,137 @@
const request = require('request');
const db = require('../utils/db_config');
const { getCurrentDateTime } = require("./helper");
const crypto = require('crypto');
function generateHMACSHA256(input, key) {
const hmac = crypto.createHmac('sha256', key);
hmac.update(input, 'utf8');
return hmac.digest('hex');
}
function getHashCode(investor_id, request_id) {
const inputString_GetInvestorDashboard = `${request_id}||${investor_id}||${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
return hash_GetInvestorDashboard
}
//get Request_Id and Investor_Id....
const getReqAndInvId = async () => {
let allInvestorId = await db.investorSummary.findAll({
attributes: ['investor_id', 'request_id']
});
let sendId = JSON.stringify(allInvestorId, null, 2)
fetchReqAndInvId(sendId);
}
// Send Request_Id and Investor_Id to the getTransactionById fun
const fetchReqAndInvId = async (sendId) => {
let data = JSON.parse(sendId)
console.log("data",data.length)
for (let i = 0; i < data.length; i++) {
let checkInvestorId = data[i].investor_id;
let checkRequestId = data[i].request_id;
if (checkInvestorId && checkRequestId) {
setTimeout(() => {
getTransactionById(checkInvestorId, checkRequestId)
}, 10);
}
}
}
const getTransactionById = (checkInvestorId, checkRequestId) => {
try {
var options = {
method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetTransactionById',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
mid: "M00201",
checksum: getHashCode(checkInvestorId, checkRequestId),
timestamp: getCurrentDateTime(),
investor_id: checkInvestorId.toString(),
request_id: checkRequestId.toString()
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
if (response.body) {
setTimeout(() => {
fetchTransactionId(response.body);
}, 10);
}
});
} catch {
console.log(error, "ERROR...____");
}
}
const fetchTransactionId = async (data) => {
try {
let idDetails = JSON.parse(data);
let trnId = idDetails.data;
let item = {};
item.request_id = trnId.id,
item.investor_id = trnId.investor_id,
item.amount = trnId.amount,
item.transaction_type = trnId.transaction_type,
item.transaction_sub_type = trnId.transaction_sub_type,
item.withdrawal_method = trnId.withdrawal_method,
item.manual_parameters = trnId.manual_parameters,
item.old_investment_id = trnId.old_investment_id,
item.scheme_id = trnId.scheme_id,
item.mode = trnId.mode,
item.transaction_id = trnId.transaction_id,
item.order_id = trnId.order_id,
item.settlement_utr = trnId.settlement_utr,
item.transaction_source = trnId.transaction_source,
item.approval_status = trnId.approval_status,
item.transaction_status = trnId.transaction_status,
item.created_at = trnId.created_at,
item.authenticated_at = trnId.authenticated_at,
item.banking_date = trnId.banking_date,
item.execution_date = trnId.execution_date,
item.transaction_date = trnId.transaction_date,
item.ext_transaction_date = trnId.ext_transaction_date,
item.source_payment = trnId.source_payment,
item.last_updatedAt = new Date().toString()
let isRecordPresent = await handleRecordPresent(item);
if (isRecordPresent.length) {
await db.transactionById.update(item, {
where: {
request_id: item.request_id
}
});
} else {
await db.transactionById.create(item);
}
console.log("done--------->")
} catch (err) {
console.log(err, "ERROR.........");
}
}
const handleRecordPresent = async (item) => {
let id = item.request_id;
try {
let query = `select * from dbo.P2P_Liquiloans_Inv_Transactions where request_id= '${id}'`;
return await db.sequelize.query(query, { type: db.sequelize.QueryTypes.SELECT });
} catch (err) {
console.log("isInvestorPresent", err.message)
}
}
module.exports = {
getReqAndInvId
}

+ 1
- 0
model/investorSummary.js View File

@ -35,6 +35,7 @@ module.exports = function (sequelize, DataTypes) {
request_id: { type: DataTypes.INTEGER, allowNull: true }, request_id: { type: DataTypes.INTEGER, allowNull: true },
source: { type: DataTypes.STRING, allowNull: true }, source: { type: DataTypes.STRING, allowNull: true },
created_at: { type: DataTypes.STRING, allowNull: true }, created_at: { type: DataTypes.STRING, allowNull: true },
last_updatedAt: { type: DataTypes.STRING, allowNull: true },
}, { }, {
//freezeTableName: true, // Model tableName will be the same as the model name //freezeTableName: true, // Model tableName will be the same as the model name
timestamps: false, timestamps: false,


+ 1
- 0
model/liquiloansInvestors.js View File

@ -10,6 +10,7 @@ module.exports = function (sequelize, DataTypes) {
ifa_id: { type: DataTypes.STRING, allowNull: true }, ifa_id: { type: DataTypes.STRING, allowNull: true },
created_at: { type: DataTypes.STRING, allowNull: true }, created_at: { type: DataTypes.STRING, allowNull: true },
rm_name: { type: DataTypes.STRING, allowNull: true }, rm_name: { type: DataTypes.STRING, allowNull: true },
last_updatedAt: { type: DataTypes.STRING, allowNull: true },
}, { }, {
//freezeTableName: true, // Model tableName will be the same as the model name //freezeTableName: true, // Model tableName will be the same as the model name
timestamps: false, timestamps: false,


+ 38
- 0
model/transactionById.js View File

@ -0,0 +1,38 @@
// P2P_Liquiloans_Inv_Transaction
module.exports = function (sequelize, DataTypes) {
const liquiloansTransaction = sequelize.define('P2P_Liquiloans_Inv_Transactions', {
request_id: { type: DataTypes.INTEGER, allowNull: false, unique: true },
investor_id: { type: DataTypes.INTEGER, allowNull: true },
amount: { type: DataTypes.INTEGER, allowNull: true },
transaction_type: { type: DataTypes.STRING, allowNull: true },
transaction_sub_type: { type: DataTypes.STRING, allowNull: true },
withdrawal_method: { type: DataTypes.STRING, allowNull: true },
manual_parameters: { type: DataTypes.STRING, allowNull: true },
old_investment_id: { type: DataTypes.STRING, allowNull: true },
scheme_id: { type: DataTypes.INTEGER, allowNull: true },
mode: { type: DataTypes.STRING, allowNull: true },
transaction_id: { type: DataTypes.STRING, allowNull: true },
order_id: { type: DataTypes.STRING, allowNull: true },
settlement_utr: { type: DataTypes.STRING, allowNull: true },
transaction_source: { type: DataTypes.STRING, allowNull: true },
approval_status: { type: DataTypes.STRING, allowNull: true },
transaction_status: { type: DataTypes.STRING, allowNull: true },
created_at: { type: DataTypes.STRING, allowNull: true },
authenticated_at: { type: DataTypes.STRING, allowNull: true },
banking_date: { type: DataTypes.STRING, allowNull: true },
execution_date: { type: DataTypes.STRING, allowNull: true },
transaction_date: { type: DataTypes.STRING, allowNull: true },
ext_transaction_date: { type: DataTypes.STRING, allowNull: true },
source_payment: { type: DataTypes.STRING, allowNull: true },
last_updatedAt: { type: DataTypes.STRING, allowNull: true },
}, {
timestamps: false,
}
);
return liquiloansTransaction
}

+ 9
- 2
routes/script.js View File

@ -2,15 +2,22 @@ const express = require('express');
const { route } = require("express/lib/application"); const { route } = require("express/lib/application");
const { getAllInvestorId } = require('../controller/getInvestmentSumarry'); const { getAllInvestorId } = require('../controller/getInvestmentSumarry');
const { fetchInvestorDetails } = require('../controller/getAllInvestor'); const { fetchInvestorDetails } = require('../controller/getAllInvestor');
const { getReqAndInvId } = require('../controller/getTransactionById');
const router = express.Router(); const router = express.Router();
router.get("/api/all_investor", (req, res) => {
fetchInvestorDetails()
})
router.get("/api/v1", (req, res) => { router.get("/api/v1", (req, res) => {
getAllInvestorId() getAllInvestorId()
}) })
router.get("/api/all_investor", (req, res) => {
fetchInvestorDetails()
router.get("/api/transaction_id", (req, res) => {
getReqAndInvId()
}) })
module.exports = router; module.exports = router;

+ 1
- 0
utils/db_config.js View File

@ -39,6 +39,7 @@ db.sequelize = sequelize;
db.liquiloansInvestors = require('../model/liquiloansInvestors')(sequelize, Sequelize); db.liquiloansInvestors = require('../model/liquiloansInvestors')(sequelize, Sequelize);
db.investorSummary = require('../model/investorSummary')(sequelize, Sequelize); db.investorSummary = require('../model/investorSummary')(sequelize, Sequelize);
db.transactionById = require('../model/transactionById')(sequelize, Sequelize);
module.exports = db; module.exports = db;


Loading…
Cancel
Save

Powered by TurnKey Linux.