Browse Source

feat - final step for script an script & folder structure, seperated querys, add multiple scheduler

pull/1/head
khanshanawaz10 1 year ago
parent
commit
8eb0085134
13 changed files with 167 additions and 78 deletions
  1. +3
    -1
      app.js
  2. +13
    -0
      controller/Errorlog/index.js
  3. +20
    -18
      controller/getAllInvestor/index.js
  4. +16
    -0
      controller/getAllInvestor/query.js
  5. +2
    -1
      controller/getHashvalue.js
  6. +34
    -25
      controller/getInvestmentSummary/index.js
  7. +16
    -0
      controller/getInvestmentSummary/query.js
  8. +18
    -18
      controller/getTransactionById/index.js
  9. +16
    -0
      controller/getTransactionById/query.js
  10. +3
    -2
      controller/helper.js
  11. +4
    -6
      routes/script.js
  12. +5
    -4
      utils/consts.js
  13. +17
    -3
      utils/scheduler.js

+ 3
- 1
app.js View File

@ -37,7 +37,9 @@ app.use('/script', scriptRouter);
/* SCHEDULER */
//scheduler.routineFetchInvestors();
scheduler.routineFetchAllInvestors();
scheduler.routineGetInvestmentSummary();
scheduler.routineGetTransactionById();
// catch 404 and forward to error handler


+ 13
- 0
controller/Errorlog/index.js View File

@ -0,0 +1,13 @@
const db = require("../../utils/db_config");
const { getCurrentDateTime } = require("../helper");
function errorLogStatus(error = null, funName = null) {
let query = `INSERT INTO providentialadvisory.dbo.User_log
(client_code, request, status, response, created_date, created_by, api_name, Open_Close_Status, IPAddress, DeviceId, [Source], Header)
VALUES('23232323', '${error}', 0, '', '${getCurrentDateTime()}', '', '${funName}', 0, '', '', '', '')`;
return db.sequelize.query(query, { type: db.sequelize.QueryTypes.INSERT });
}
module.exports = {
errorLogStatus
}

controller/getAllInvestor.js → controller/getAllInvestor/index.js View File

@ -1,10 +1,13 @@
'use strict'
const request = require('request');
const db = require('../utils/db_config');
const { getCurrentDateTime } = require("./helper");
const {getAllInvestorId} = require('./getInvestmentSumarry')
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 { errorLogStatus } = require('../Errorlog');
function generateHMACSHA256(input, key) {
@ -15,7 +18,7 @@ function generateHMACSHA256(input, key) {
function getHashCode(req) {
const inputString_GetInvestorDashboard = `||${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const key = HASH_KEY;
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
return hash_GetInvestorDashboard
@ -28,7 +31,7 @@ const fetchInvestorDetails = ((req, res) => {
})
const getAllInvstorData = async () => {
var options = {
method: 'POST',
url: 'https://supply-integration.liquiloans.com/api/v2/GetAllInvestors',
@ -51,14 +54,13 @@ const getAllInvstorData = async () => {
const getAllInvstorDataStore = async (body) => {
try {
const records = JSON.parse(body)
let item = records?.data
let storeData = [];
if (item.length) {
for (let i = 0; i < item?.length; i++) {
let log = await isInvestorPresent(item[i].investor_id);
let log = await getInvestorIdQuery(item[i].investor_id);
if (log == 0) {
let data = {};
data.investor_id = item[i].investor_id,
@ -72,26 +74,26 @@ const getAllInvstorDataStore = async (body) => {
data.rm_name = item[i].rm_name,
data.last_updatedAt = new Date
storeData.push(data);
storeData.push(data);
}
}
await db.liquiloansInvestors.bulkCreate(storeData);
}
} catch (err) {
console.log(err, "ERROR...........");
errorLogStatus(err, "nodeJs_liquiloan_getAllInvstorDataStore")
}
}
const isInvestorPresent = async (id) => {
try {
let query = `select * from dbo.P2P_Liquiloans_Investors where investor_id= '${id}'`;
return await db.sequelize.query(query, { type: db.sequelize.QueryTypes.SELECT });
// const isInvestorPresent = async (id) => {
// try {
// await getInvestorIdQuery(id)
} catch (err) {
console.log("isInvestorPresent", err.message)
}
}
// } catch (err) {
// // console.log("isInvestorPresent", err.message)
// errorLogStatus(err, "nodeJs_liquiloan_isInvestorPresent")
// }
// }
module.exports = {

+ 16
- 0
controller/getAllInvestor/query.js View File

@ -0,0 +1,16 @@
const db = require("../../utils/db_config");
const { errorLogStatus } = require("../Errorlog");
async function getInvestorIdQuery(id) {
try {
let query = `select * from dbo.P2P_Liquiloans_Investors where investor_id= '${id}'`;
return await db.sequelize.query(query, { type: db.sequelize.QueryTypes.SELECT });
} catch (error) {
// console.log("isInvestorPresent", err.message)
errorLogStatus(error, "nodeJs_liquiloan_isInvestorPresent")
}
}
module.exports = {
getInvestorIdQuery
}

+ 2
- 1
controller/getHashvalue.js View File

@ -1,4 +1,5 @@
const crypto = require('crypto');
const { HASH_KEY } = require('../utils/consts');
function generateHMACSHA256(input, key) {
const hmac = crypto.createHmac('sha256', key);
@ -10,7 +11,7 @@ function getHashCode(type) {
const inputString = "||2023-11-22 14:57:38";
const inputString_GetInvestorDashboard = "368907||2023-11-22 14:57:38";
const inputString_GetTransactionById = "5151974||368907||2023-11-22 14:57:38";
const key = "27E6A91CEE689";
const key = HASH_KEY;
const hash = generateHMACSHA256(inputString, key);
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);


controller/getInvestmentSumarry.js → controller/getInvestmentSummary/index.js View File

@ -1,10 +1,13 @@
'use strict'
const request = require("request");
const db = require('../utils/db_config');
const db = require('../../utils/db_config');
const crypto = require('crypto');
const {getReqAndInvId} = require('./getTransactionById')
const { getCurrentDateTime } = require("./helper");
const { getReqAndInvId } = require('../getTransactionById')
const { getCurrentDateTime } = require("../helper");
const { HASH_KEY } = require("../../utils/consts");
const { getInvSummaryIdQuery } = require("./query");
const { errorLogStatus } = require("../Errorlog");
function generateHMACSHA256(input, key) {
const hmac = crypto.createHmac('sha256', key);
@ -14,7 +17,7 @@ function generateHMACSHA256(input, key) {
function getHashCode(req) {
const inputString_GetInvestorDashboard = `${req}||${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const key = HASH_KEY;
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
return hash_GetInvestorDashboard
@ -24,7 +27,7 @@ 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)
await createLiquiloanInvestor(data[i].investor_id, i)
}
}
@ -37,7 +40,7 @@ const getAllInvestorId = async () => {
};
const createLiquiloanInvestor = (investor_id,index) => {
const createLiquiloanInvestor = (investor_id, index) => {
var options = {
method: 'POST',
@ -53,7 +56,7 @@ const createLiquiloanInvestor = (investor_id,index) => {
})
};
request(options, function (error, response,body) {
request(options, function (error, response, body) {
if (error) throw new Error(error);
const data = JSON.parse(body);
let pastData = data?.data.past_investments;
@ -64,17 +67,15 @@ const createLiquiloanInvestor = (investor_id,index) => {
if (currentData) {
getUrlAndStore(currentData);
}
console.log(index,"investor_id-->",investor_id,"currentData-->",currentData.length,"pastData-->",pastData.length)
console.log(index, "investor_id-->", investor_id, "currentData-->", currentData.length, "pastData-->", pastData.length)
});
}
const getUrlAndStore = async (callsData) => {
try {
let summary = []
for (let i = 0; i < callsData.length; i++) {
let checkTrnId = await isRequestIdPresent(callsData[i].request_id);
let checkTrnId = await getInvSummaryIdQuery(callsData[i].request_id);
if (checkTrnId == 0) {
let record = {};
record.transaction_id = callsData[i].transaction_id,
@ -110,32 +111,40 @@ const getUrlAndStore = async (callsData) => {
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()
record.created_at = new Date().toString()
record.last_updatedAt = new Date().toString()
summary.push(record);
} else {
let record = {
...callsData[i],
last_updatedAt: new Date().toString()
}
await db.transactionById.update(record, {
where: {
transaction_id: record.transaction_id
}
});
}
}
if(summary.length){
if (summary.length) {
await db.investorSummary.bulkCreate(summary);
}
}
catch (err) {
console.log(err, "ERROR.........");
errorLogStatus(err, "nodeJs_liquiloan_getUrlAndStore")
}
}
// 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)
}
}
// const isRequestIdPresent = async (id) => {
// try {
// getInvSummaryIdQuery(id)
// } catch (err) {
// errorLogStatus(err, "nodeJs_liquiloan_isRequestIdPresent")
// }
// }
module.exports = {
getAllInvestorId

+ 16
- 0
controller/getInvestmentSummary/query.js View File

@ -0,0 +1,16 @@
const db = require("../../utils/db_config");
const { errorLogStatus } = require("../Errorlog");
async function getInvSummaryIdQuery(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 (error) {
errorLogStatus(error, "nodeJs_liquiloan_isRequestIdPresent")
}
}
module.exports = {
getInvSummaryIdQuery
}

controller/getTransactionById.js → controller/getTransactionById/index.js View File

@ -1,7 +1,10 @@
const request = require('request');
const db = require('../utils/db_config');
const { getCurrentDateTime } = require("./helper");
const db = require('../../utils/db_config');
const { getCurrentDateTime } = require("../helper");
const crypto = require('crypto');
const { HASH_KEY } = require('../../utils/consts');
const { getInvTransIdQuery } = require('./query');
const { errorLogStatus } = require('../Errorlog');
function generateHMACSHA256(input, key) {
@ -12,7 +15,7 @@ function generateHMACSHA256(input, key) {
function getHashCode(investor_id, request_id) {
const inputString_GetInvestorDashboard = `${request_id}||${investor_id}||${getCurrentDateTime()}`;
const key = "27E6A91CEE689";
const key = HASH_KEY;
const hash_GetInvestorDashboard = generateHMACSHA256(inputString_GetInvestorDashboard, key);
return hash_GetInvestorDashboard
@ -30,7 +33,6 @@ const getReqAndInvId = async () => {
// 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;
@ -68,7 +70,7 @@ const getTransactionById = (checkInvestorId, checkRequestId) => {
}
});
} catch {
console.log(error, "ERROR...____");
errorLogStatus(err, "nodeJs_liquiloan_getTransactionById")
}
}
@ -102,9 +104,9 @@ const fetchTransactionId = async (data) => {
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()
item.last_updatedAt = getCurrentDateTime()
let isRecordPresent = await handleRecordPresent(item);
let isRecordPresent = await getInvTransIdQuery(item);
if (isRecordPresent.length) {
await db.transactionById.update(item, {
where: {
@ -116,20 +118,18 @@ const fetchTransactionId = async (data) => {
}
console.log("done--------->")
} catch (err) {
console.log(err, "ERROR.........");
errorLogStatus(err, "nodeJs_liquiloan_fetchTransactionId")
}
}
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)
}
}
// const handleRecordPresent = async (item) => {
// let id = item.request_id;
// try {
// getInvTransIdQuery(id)
// } catch (err) {
// errorLogStatus(err, "nodeJs_liquiloan_handleRecordPresent")
// }
// }
module.exports = {

+ 16
- 0
controller/getTransactionById/query.js View File

@ -0,0 +1,16 @@
const db = require("../../utils/db_config");
const { errorLogStatus } = require("../Errorlog");
async function getInvTransIdQuery(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 (error) {
errorLogStatus(error, "nodeJs_liquiloan_handleRecordPresent")
}
}
module.exports = {
getInvTransIdQuery
}

+ 3
- 2
controller/helper.js View File

@ -1,3 +1,5 @@
const db = require("../utils/db_config");
function getCurrentDateTime() {
var date = new Date();
var dateStr =
@ -10,7 +12,6 @@ function getCurrentDateTime() {
return dateStr
}
module.exports = {
getCurrentDateTime
getCurrentDateTime,
}

+ 4
- 6
routes/script.js View File

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


+ 5
- 4
utils/consts.js View File

@ -12,16 +12,16 @@ const ERROR_MESSAGE = "Oops,something went wrong";
const BUCKET_NAME_NIVESH = "nivesh-call-logs/recording";
const S3_BUCKET_NIVESH_CALL_URL= "https://nivesh-call-logs.s3.ap-south-1.amazonaws.com/recording/";
const S3_BUCKET_NIVESH_CALL_URL = "https://nivesh-call-logs.s3.ap-south-1.amazonaws.com/recording/";
const BUCKET_NAME_SOA_REPORTS = "client-soa-reports/ELSS";
const S3_BUCKET_SOA_REPORTS_URL= "https://client-soa-reports.s3.ap-south-1.amazonaws.com/ELSS/";
const S3_BUCKET_SOA_REPORTS_URL = "https://client-soa-reports.s3.ap-south-1.amazonaws.com/ELSS/";
const AWS_ACCESS_KEY_ID_TEST = "AKIA2C5JCOWXUXB4T3MV";
const AWS_SECRET_KEY_TEST = "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";
const EXOTEL_AUTHTOKEN = "Basic NWE0NjY1ZDU0MGViNzk5NjQxMGQ1NWJhYzllZmI5MTVhOTgyYWU2MmRmYWFkZmM0OmU0YTgzNjEwNjI1NWM5ZDllY2QxMDNiOWQwZGFmYWQ3ZTA1YjNjNTU1NDJhZjU3NQ=="
const HASH_KEY = "27E6A91CEE689";
s3://kwikfoods/2020/
module.exports = {
ERROR_500,
@ -39,5 +39,6 @@ module.exports = {
S3_BUCKET_SOA_REPORTS_URL,
AWS_ACCESS_KEY_ID_TEST,
AWS_SECRET_KEY_TEST,
EXOTEL_AUTHTOKEN
EXOTEL_AUTHTOKEN,
HASH_KEY
};

+ 17
- 3
utils/scheduler.js View File

@ -4,14 +4,28 @@ const cron = require('node-cron');
const routineFetchInvestors = () => {
cron.schedule(process.env.SCHEDULER_RULE_EXOTEL_CALL, () => {
const routineFetchAllInvestors = () => {
cron.schedule(process.env.SCHEDULER_RULE_FETCH_ALL_INVESTOR, () => {
console.log("running scheduler");
// recordingController.callExotelRecording();
})
};
const routineGetInvestmentSummary = () => {
cron.schedule(process.env.SCHEDULER_RULE_INVESTMENT_SUMMARY, () => {
console.log("running scheduler");
// recordingController.callExotelRecording();
})
};
const routineGetTransactionById = () => {
cron.schedule(process.env.SCHEDULER_RULE_TRANS_ID, () => {
console.log("running scheduler");
// recordingController.callExotelRecording();
})
};
module.exports = {
routineFetchInvestors,
routineFetchAllInvestors,
routineGetInvestmentSummary,
routineGetTransactionById
};

Loading…
Cancel
Save

Powered by TurnKey Linux.