diff --git a/app/controllers/cibil.controller.js b/app/controllers/cibil.controller.js index fbdb68e..a2d8141 100644 --- a/app/controllers/cibil.controller.js +++ b/app/controllers/cibil.controller.js @@ -562,7 +562,7 @@ exports.ConsolidatedActiveAndClosedLoansReviewAction =async (req, res) => try { - LoanData = await sequelize.query("SELECT [losid],STRING_AGG(ref_no,',')as ref_no,STRING_AGG(consumer_name, ',') as consumer_name,MAX(account_type) as account_type,count(*) as loan_count, MAX(ownership) as ownership,MAX(reported_and_certified_date) as reported_and_certified_date,MAX(opened_date) as opened_date,MAX(sanctioned_amount) assanctioned_amount,MAX(current_balance) as current_balance,MAX(repayment_tenure) asrepayment_tenure,MAX(emi_amount) as emi_amount, MAX(overdue_amount) as overdue_amount,MAX(status) as status, MAX(current_dpd) as current_dpd, MAX(highest_dpd_month_wise_bucket_or_count_0_to_6) as highest_dpd_month_wise_bucket_or_count_0_to_6,MAX(highest_dpd_month_wise_bucket_or_count_07_to_12) as highest_dpd_month_wise_bucket_or_count_07_to_12,MAX(highest_dpd_month_wise_bucket_or_count_13_to_24) as highest_dpd_month_wise_bucket_or_count_13_to_24,MAX(highest_dpd_month_wise_bucket_or_count_25_to_36) as highest_dpd_month_wise_bucket_or_count_25_to_36,MAX(DateClosed) as DateClosed, [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = '"+req.query.losid+"' GROUP BY [grp_str], [losid]"); + LoanData = await sequelize.query("SELECT [losid],STRING_AGG(id,',')as id,STRING_AGG(ref_no,',')as ref_no,STRING_AGG(consumer_name, ',') as consumer_name,MAX(account_type) as account_type,count(*) as loan_count, MAX(ownership) as ownership,MAX(reported_and_certified_date) as reported_and_certified_date,MAX(opened_date) as opened_date,MAX(sanctioned_amount) assanctioned_amount,MAX(current_balance) as current_balance,MAX(repayment_tenure) asrepayment_tenure,MAX(emi_amount) as emi_amount, MAX(overdue_amount) as overdue_amount,MAX(status) as status, MAX(current_dpd) as current_dpd, MAX(highest_dpd_month_wise_bucket_or_count_0_to_6) as highest_dpd_month_wise_bucket_or_count_0_to_6,MAX(highest_dpd_month_wise_bucket_or_count_07_to_12) as highest_dpd_month_wise_bucket_or_count_07_to_12,MAX(highest_dpd_month_wise_bucket_or_count_13_to_24) as highest_dpd_month_wise_bucket_or_count_13_to_24,MAX(highest_dpd_month_wise_bucket_or_count_25_to_36) as highest_dpd_month_wise_bucket_or_count_25_to_36,MAX(DateClosed) as DateClosed, [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = '"+req.query.losid+"' GROUP BY [grp_str], [losid]"); if(LoanData.length != 0) { @@ -579,7 +579,7 @@ exports.ConsolidatedActiveAndClosedLoansReviewAction =async (req, res) => }else{ subValue = await OutputActiveAndClosedLoans.findAll({raw:true,where:{losid:value.losid,grp_str:value.grp_str}}) .catch(err=>{ }); - Object.assign(value , {children : subValue }); + Object.assign(value , {children : subValue.map(v => ({...v, children: null})) }); FinalLoanData.push(value); if (index === LoanData[0].length -1) { resolve(FinalLoanData); } } @@ -828,13 +828,13 @@ exports.test = async (req, res) => - // x = '01-01-1996'; - // data = { - // "date" : null || moment(new Date(x)).format("YYYY-MM-DD") - // } + x = null; + data = { + "date" : await Helper.convertDateFormat(x) + }; - // console.log(data); - // res.send({"data":data}); + console.log(data); + res.send({"data":data}); } catch(err) { res.status(500).send({'status':404, diff --git a/app/services/cibil.controller.helper.js b/app/services/cibil.controller.helper.js index e88679c..9842495 100644 --- a/app/services/cibil.controller.helper.js +++ b/app/services/cibil.controller.helper.js @@ -1,7 +1,7 @@ //const { sequelize} = require('../models'); const { logMsg } = require('../services/logger.js'); const request = require('request'); - +const moment = require('moment'); @@ -178,6 +178,24 @@ function getLoginToken() { } +function convertDateFormat(DateValue) { + try { + return new Promise((resolve, reject) => { + if(DateValue == null) + { + resolve(null); + }else{ + data = moment( new Date( DateValue ) ).format("YYYY-MM-DD"); + resolve(data); + } + }); + } + catch (error) { + console.log(error); + } +} + + module.exports = { @@ -186,6 +204,7 @@ module.exports = { cibilInputDataApiCall : cibilInputDataApiCall, cibilOutputGenerateApiCall : cibilOutputGenerateApiCall, panListApiCall : panListApiCall , - getLoginToken : getLoginToken + getLoginToken : getLoginToken, + convertDateFormat : convertDateFormat } \ No newline at end of file diff --git a/app/services/cibil.datainsert.helper.js b/app/services/cibil.datainsert.helper.js index 1dd7269..462180e 100644 --- a/app/services/cibil.datainsert.helper.js +++ b/app/services/cibil.datainsert.helper.js @@ -1,6 +1,7 @@ const { sequelize,ConBorrowDetail,ConAccountTranscation,ConAddressDetail,ConDPDTranscation,ConIDDetail,ConEnquiryDetail,ConPhoneDetail,ConScoreDetail} = require('../models'); const { logMsg } = require('../services/logger.js'); - +const Helper = require('../services/cibil.controller.helper.js'); +const moment = require('moment'); function consumerDataInsert(data) { @@ -21,24 +22,24 @@ function consumerDataInsert(data) EnquiryMemberUserID: value.enquiryMemberUserID, SubjectReturnCode: value.subjectReturnCode, EnquiryControlNumber: value.enquiryControlNumber, - DateTimeProcessed: moment(new Date( value.dateTimeProcessed)).format("YYYY-MM-DD"), + DateTimeProcessed: await Helper.convertDateFormat( value.dateTimeProcessed), ConsumerNameField1: value.consumerNameField1, ConsumerNameField2: value.consumerNameField2, ConsumerNameField3: value.consumerNameField3, ConsumerNameField4: value.consumerNameField4, ConsumerNameField5: value.consumerNameField5, - DateofBirth: moment(new Date( value.dateofBirth)).format("YYYY-MM-DD"), + DateofBirth: await Helper.convertDateFormat( value.dateofBirth), Gender: value.gender, - DateofEntryforErrorCode: moment(new Date( value.dateofEntryforErrorCode)).format("YYYY-MM-DD"), + DateofEntryforErrorCode: await Helper.convertDateFormat( value.dateofEntryforErrorCode), ErrorSegmentTag: value.errorSegmentTag, ErrorCode: value.errorCode, - DateofEntryforCIBILRemarksCode: moment(new Date( value.dateofEntryforCIBILRemarksCode)).format("YYYY-MM-DD"), + DateofEntryforCIBILRemarksCode: await Helper.convertDateFormat(value.dateofEntryforCIBILRemarksCode), CIBILRemarks: value.cibilRemarks, DateofEntryforErrorDisputeRemarksCode: value.dateofEntryforErrorDisputeRemarksCode, ErrorDisputeRemarksCode: value.errorDisputeRemarksCode, ErrorDisputeRemarksCode2: value.errorDisputeRemarksCode2, AccountType: value.accountType, - DateReportedAndCertified: moment(new Date( value.dateReportedAndCertified)).format("YYYY-MM-DD"), + DateReportedAndCertified: await Helper.convertDateFormat( value.dateReportedAndCertified), Occupation: value.occupation, Income: value.income, NetGrossIncomeIndicator: value.netGrossIncomeIndicator, @@ -51,7 +52,7 @@ function consumerDataInsert(data) ErrorDisputeRemarksCode1: value.errorDisputeRemarksCode1, ATErrorDisputeRemarksCode1: value.atErrorDisputeRemarksCode1, ATErrorDisputeRemarksCode2: value.atErrorDisputeRemarksCode2, - DateOfEntry: moment(new Date( value.dateOfEntry)).format("YYYY-MM-DD"), + DateOfEntry: await Helper.convertDateFormat( value.dateOfEntry), DisputeRemarksLine: value.disputeRemarksLine, EMailID: value.eMailID, AccountNumber: value.accountNumber @@ -991,7 +992,7 @@ function commercialDataInsert(data) -const Helper = require('../services/cibil.controller.helper.js'); + const { InBorrowerDetail,InEnquiryDetail,InCreditFacility,InDpdTranscationTable} = require('../models') async function consumerIntermediateDataInsert(losid,refNo)