diff --git a/app/controllers/cibil.controller.js b/app/controllers/cibil.controller.js index 3e50de0..b944f17 100644 --- a/app/controllers/cibil.controller.js +++ b/app/controllers/cibil.controller.js @@ -191,9 +191,9 @@ exports.ConsolidatedActiveAndClosedLoansDetailsList =async (req, res) => //ActiveLoanData = await OutputActiveAndClosedLoans.findAll({raw : true ,attributes:[ sequelize.literal("STRING_AGG(consumer_name,',')") ],attributes: {exclude: ['id','ref_no','is_active','createdAt','createdby','updatedAt','updatedby']} , where:{losid:req.query.losid , DateClosed:null },group: ['grp_str','losid','account_type','ownership','reported_and_certified_date','opened_date','sanctioned_amount','current_balance','repayment_tenure','emi_amount','overdue_amount','status','current_dpd','highest_dpd_month_wise_bucket_or_count_0_to_6','highest_dpd_month_wise_bucket_or_count_07_to_12','highest_dpd_month_wise_bucket_or_count_13_to_24','highest_dpd_month_wise_bucket_or_count_25_to_36','DateClosed','consumer_name']}); - ActiveLoanData = await sequelize.query("SELECT [losid],STRING_AGG(consumer_name, ',') as consumer_name, [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed], [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = N'MW112233' AND [OutputActiveAndClosedLoans].[DateClosed] IS NULL GROUP BY [grp_str], [losid], [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed]"); + ActiveLoanData = await sequelize.query("SELECT [losid],STRING_AGG(consumer_name, ',') as consumer_name, [account_type],count(*) as loan_count, [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed], [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = '"+req.query.losid+"' AND [OutputActiveAndClosedLoans].[DateClosed] IS NULL GROUP BY [grp_str], [losid], [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed]"); //ClosedLoanData = await OutputActiveAndClosedLoans.findAll({raw : true ,attributes:[ sequelize.literal("STRING_AGG(consumer_name,',')") ],attributes: {exclude: ['id','ref_no','is_active','createdAt','createdby','updatedAt','updatedby']}, where:{losid:req.query.losid , DateClosed:{ [Op.ne]: null} },group: ['grp_str','losid','account_type','ownership','reported_and_certified_date','opened_date','sanctioned_amount','current_balance','repayment_tenure','emi_amount','overdue_amount','status','current_dpd','highest_dpd_month_wise_bucket_or_count_0_to_6','highest_dpd_month_wise_bucket_or_count_07_to_12','highest_dpd_month_wise_bucket_or_count_13_to_24','highest_dpd_month_wise_bucket_or_count_25_to_36','DateClosed','consumer_name']}); - ClosedLoanData = await sequelize.query("SELECT [losid],STRING_AGG(consumer_name, ',') as consumer_name, [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed], [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = N'MW112233' AND [OutputActiveAndClosedLoans].[DateClosed] IS NOT NULL GROUP BY [grp_str], [losid], [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed]"); + ClosedLoanData = await sequelize.query("SELECT [losid],STRING_AGG(consumer_name, ',') as consumer_name, [account_type],count(*) as loan_count, [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed], [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = '"+req.query.losid+"' AND [OutputActiveAndClosedLoans].[DateClosed] IS NOT NULL GROUP BY [grp_str], [losid], [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed]"); if(ActiveLoanData.length != 0 || ClosedLoanData.length != 0) { @@ -577,9 +577,7 @@ exports.test = async (req, res) => // DataInsertHelper.consumerDataInsert(data); // res.send(data); - PanList = await Helper.panListApiCall('MW112233'); - - res.send({'status':200 , message:"Success." ,'data':PanList}); + // query = " test_group_loans @los_id = 'MW112233', @ref_no = '202201121115264000000' "; // sequelize.query(query).then(async(data) => { @@ -666,27 +664,29 @@ exports.starter = async (req, res) => { //cibil data api call CibilData = await Helper.cibilInputDataApiCall(PanListData.losid,PanListData.PAN,PanListData.cibil_type); + ref_no = CibilData.lstConsumerBorrowersDetails[0].memberReferenceNumber; //insert cibil data in to input tables DataInsertHelper.consumerDataInsert(CibilData); //move cibil data from input table to intermediate table - DataInsertHelper.consumerIntermediateDataInsert(); + DataInsertHelper.consumerIntermediateDataInsert(PanListData.losid,ref_no); //cibil output data generating python script api call - Helper.cibilOutputGenerateApiCall(losid,ref_no,cibil_type); + Helper.cibilOutputGenerateApiCall(losid,ref_no,cibil_type,1); } else { //cibil data api call CibilData = await Helper.cibilInputDataApiCall(PanListData.losid,PanListData.PAN,PanListData.cibil_type); + ref_no = CibilData.lstborrowerProfiles[0].applicationRefno; //insert cibil data in to input tables DataInsertHelper.commercialDataInsert(CibilData); //move cibil data from input table to intermediate table - DataInsertHelper.commercialIntermediateDataInsert(); + DataInsertHelper.commercialIntermediateDataInsert(PanListData.losid,ref_no); //cibil output data generating python script api call - Helper.cibilOutputGenerateApiCall(losid,ref_no,cibil_type); + Helper.cibilOutputGenerateApiCall(losid,ref_no,cibil_type,1); } }).catch(err=>{ }); diff --git a/app/services/cibil.controller.helper.js b/app/services/cibil.controller.helper.js index d3c6070..a776eea 100644 --- a/app/services/cibil.controller.helper.js +++ b/app/services/cibil.controller.helper.js @@ -98,25 +98,20 @@ try { } -async function cibilOutputGenerateApiCall(losid,ref_no,cibil_type) { +async function cibilOutputGenerateApiCall(losid,ref_no,cibil_type,output_type) { try { var promises = new Promise(async(resolve, reject) => { ActionData = [1,2,3]; ActionData.forEach((value,index,array) => { - let url = process.env.PYTHON_SCRIPT_API+"cibil?reference_number="+ref_no+"&los_id="+losid+"&cibil_type="+cibil_type+"&action="+value; + let url = process.env.PYTHON_SCRIPT_API+"cibil?reference_number="+ref_no+"&los_id="+losid+"&cibil_type="+cibil_type+"&action="+value+"&output_type="+output_type; - request({ - url: url, - method: "GET" - }, function (error, response, body){ - //logMsg - }) + request({url: url,method: "GET" }, function (error, response, body){ }) if (index === array.length -1) { resolve(); } - }); - }); + });//end of foreach + });//end of Promise promises.then(async()=>{ return true; }); diff --git a/app/services/cibil.datainsert.helper.js b/app/services/cibil.datainsert.helper.js index dbfd5c0..1f728f4 100644 --- a/app/services/cibil.datainsert.helper.js +++ b/app/services/cibil.datainsert.helper.js @@ -992,8 +992,6 @@ function commercialDataInsert(data) const Helper = require('../services/cibil.controller.helper.js'); - - const { InBorrowerDetail,InEnquiryDetail,InCreditFacility,InDpdTranscationTable} = require('../models') async function consumerIntermediateDataInsert(losid,refNo)