From d5e936a7f05090541063b15ce9c6b0265dc8cc30 Mon Sep 17 00:00:00 2001 From: amol Date: Wed, 3 Jan 2024 16:47:21 +0530 Subject: [PATCH] Client code update --- controller/getAllInvestor/index.js | 43 ++++++++++++++++++------ controller/getAllInvestor/query.js | 13 ++++++- controller/getInvestmentSummary/index.js | 14 ++++---- model/liquiloansInvestors.js | 1 + 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/controller/getAllInvestor/index.js b/controller/getAllInvestor/index.js index 41f1bfa..086d3a9 100644 --- a/controller/getAllInvestor/index.js +++ b/controller/getAllInvestor/index.js @@ -3,10 +3,10 @@ const request = require('request'); const db = require('../../utils/db_config'); const { getCurrentDateTime } = require("../helper"); -const { getAllInvestorId } = require('../getInvestmentSummary') const crypto = require('crypto'); const { HASH_KEY } = require('../../utils/consts'); const { getInvestorIdQuery } = require('./query'); +const { getInvestorPan } = require('./query'); const { errorLogStatus } = require('../Errorlog'); @@ -22,7 +22,6 @@ function getHashCode(req) { const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key); return hash_GetInvestorDashboard - } const fetchInvestorDetails = ((req, res) => { @@ -73,11 +72,11 @@ const getAllInvstorDataStore = async (body) => { data.created_at = item[i].created_at, data.rm_name = item[i].rm_name, data.last_updatedAt = new Date - storeData.push(data); } } await db.liquiloansInvestors.bulkCreate(storeData); + getAllInvestorIdFun(); } } catch (err) { @@ -85,15 +84,37 @@ const getAllInvstorDataStore = async (body) => { } } -// const isInvestorPresent = async (id) => { -// try { -// await getInvestorIdQuery(id) +const getAllInvestorIdFun = async () => { + let allInvestorId = await db.liquiloansInvestors.findAll({where: {client_code : null}}); + let sendId = JSON.stringify(allInvestorId, null, 2) + await getClientCode(sendId); +}; -// } catch (err) { -// // console.log("isInvestorPresent", err.message) -// errorLogStatus(err, "nodeJs_liquiloan_isInvestorPresent") -// } -// } +const getClientCode = async (body) => { + try { + const records = JSON.parse(body); + let item = records; + let storeData = []; + if (item.length) { + for (let i = 0; i < item?.length; i++) { + let clientCode = await getInvestorPan(item[i].pan); + if (clientCode.length === 1) { + let data = { ...item[i] }; + data.client_code = clientCode[0].CLIENT_CODE, + storeData.push(data); + await db.liquiloansInvestors.update(data, { + where: { + investor_id: data.investor_id + } + }); + } + } + } + + } catch (err) { + errorLogStatus(err, "nodeJs_liquiloan_getClientCode") + } +} module.exports = { diff --git a/controller/getAllInvestor/query.js b/controller/getAllInvestor/query.js index 5114c87..31685d2 100644 --- a/controller/getAllInvestor/query.js +++ b/controller/getAllInvestor/query.js @@ -11,6 +11,17 @@ async function getInvestorIdQuery(id) { } +async function getInvestorPan(pan) { + try { + let query = `Select CLIENT_CODE from ClientMasterMFD Where CLIENT_PAN IN ('${pan}') and status = 1` + return await db.sequelize.query(query, { type: db.sequelize.QueryTypes.SELECT }); + } catch (error) { + errorLogStatus(error, "Error_getClientCode") + } + +} + module.exports = { - getInvestorIdQuery + getInvestorIdQuery, + getInvestorPan } \ No newline at end of file diff --git a/controller/getInvestmentSummary/index.js b/controller/getInvestmentSummary/index.js index 7a00dca..516b3cd 100644 --- a/controller/getInvestmentSummary/index.js +++ b/controller/getInvestmentSummary/index.js @@ -24,13 +24,6 @@ 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) - } -} - const getAllInvestorId = ((req, res) => { getAllInvestorIdFun(); res.send("in procress"); @@ -44,6 +37,13 @@ const getAllInvestorIdFun = async () => { fetchAllInvestorId(sendId); }; +const fetchAllInvestorId = async (sendId) => { + let data = JSON.parse(sendId) + for (let i = 0; i < data?.length; i++) { + await createLiquiloanInvestor(data[i].investor_id, i) + } +} + const createLiquiloanInvestor = (investor_id, index) => { diff --git a/model/liquiloansInvestors.js b/model/liquiloansInvestors.js index 337b8e8..eab61d8 100644 --- a/model/liquiloansInvestors.js +++ b/model/liquiloansInvestors.js @@ -10,6 +10,7 @@ module.exports = function (sequelize, DataTypes) { ifa_id: { type: DataTypes.STRING, allowNull: true }, created_at: { type: DataTypes.STRING, allowNull: true }, rm_name: { type: DataTypes.STRING, allowNull: true }, + client_code: { type: DataTypes.STRING, allowNull: true }, last_updatedAt: { type: DataTypes.STRING, allowNull: true }, }, { //freezeTableName: true, // Model tableName will be the same as the model name