From f4663ec767e9209eb71c8c6faeed51edb2b26f4c Mon Sep 17 00:00:00 2001 From: amol Date: Wed, 13 Dec 2023 10:33:37 +0530 Subject: [PATCH] data fetch and store in db from getAllInvestor api --- controller/getAllInvestor.js | 62 ++++++++++++++++++++++++++++++++++++ model/liquiloansInvestors.js | 2 +- routes/script.js | 5 +++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 controller/getAllInvestor.js diff --git a/controller/getAllInvestor.js b/controller/getAllInvestor.js new file mode 100644 index 0000000..1b7ef4a --- /dev/null +++ b/controller/getAllInvestor.js @@ -0,0 +1,62 @@ +const request = require('request'); +const db = require('../utils/db_config') + + +const fetchInvestorDetails = ((req, res) => { + getAllInvstorData(); + res.send("in procress"); +}) + +const getAllInvstorData = async () => { + + var options = { + method: 'POST', + url: 'https://supply-integration.liquiloans.com/api/v2/GetAllInvestors', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + mid: "M00201", + checksum: "e7d0ab9fb1c79796a6ae6fd22600e22129e9fef1bfe9577717f9953d0e9064ff", + timestamp: "2023-12-11 14:57:38", + filter_on: "", + filter_data: [] + }) + + }; + request(options, function (error, response) { + if (error) throw new Error(error); + getAllInvstorDataStore(response.body); + }); +} + + +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); + } + console.log("AAAADDDDDDDDDDD_________", storeData); + await db.liquiloansInvestors.bulkCreate(storeData); + } +} + + + +module.exports = { + fetchInvestorDetails +} \ No newline at end of file diff --git a/model/liquiloansInvestors.js b/model/liquiloansInvestors.js index 659ea00..7b6d1dd 100644 --- a/model/liquiloansInvestors.js +++ b/model/liquiloansInvestors.js @@ -1,5 +1,5 @@ module.exports = function (sequelize, DataTypes) { - const LiquiloansInvestorsTbl = sequelize.define('P2P_Liquiloans_Investor', { + const LiquiloansInvestorsTbl = sequelize.define('P2P_Liquiloans_Investors', { investor_id: { type: DataTypes.INTEGER, allowNull: false, unique: true }, name: { type: DataTypes.STRING, allowNull: true }, diff --git a/routes/script.js b/routes/script.js index 5db91b0..596acaa 100644 --- a/routes/script.js +++ b/routes/script.js @@ -1,6 +1,7 @@ const express = require('express'); const { route } = require("express/lib/application"); const { createLiquiloanInvestor } = require('../controller/getInvestmentSumarry'); +const { fetchInvestorDetails } = require('../controller/getAllInvestor'); const router = express.Router(); @@ -9,6 +10,10 @@ router.get("/api/v1", (req, res) => { createLiquiloanInvestor() }) +router.get("/api/all_investor", (req, res) => { + fetchInvestorDetails() +}) + /* GET users listing. */