From f921b47917a150f263ee665ab119876fef864482 Mon Sep 17 00:00:00 2001 From: surya Date: Fri, 8 Oct 2021 14:20:50 +0530 Subject: [PATCH] Surya: merge --- app/controllers/master.controller.js | 89 +++++++++++++++++++++++++++- app/controllers/test.controller.js | 11 ++-- app/routes/routes.js | 5 +- app/services/camunda.helper.js | 27 +++++---- 4 files changed, 114 insertions(+), 18 deletions(-) diff --git a/app/controllers/master.controller.js b/app/controllers/master.controller.js index 8aaed2b..c5c4171 100644 --- a/app/controllers/master.controller.js +++ b/app/controllers/master.controller.js @@ -4,8 +4,9 @@ -const {sequelize , Statementsmaster ,Sectionsmaster , Subsectionsmaster,Itemsmaster ,Fin_remarks,Fin_masters_history,Statement_type,Entityfinyears} = require('../models') +const {Entities,sequelize , Statementsmaster ,Sectionsmaster , Subsectionsmaster,Itemsmaster ,Fin_remarks,Fin_masters_history,Statement_type,Entityfinyears} = require('../models') const { logMsg } = require('../services/logger.js'); +const camundaHelper = require('../services/camunda.helper.js'); //statementmaster @@ -469,6 +470,92 @@ exports.Statementtype_insert = (req, res) => { +// API: Cheker Complete + + +exports.MakerSubmit = (req, res) => { + const req_data = req.body; + try + { + const losid = req_data.losid; + const pan = req_data.pan; + const cin = req_data.cin; + Entities.findOne({where : { losid : losid,pan : pan,cin : cin },attributes: [ 'id','process_instance_id'] }) + .then(data => { + console.log(data.dataValues.process_instance_id) + + const processInstanceId = data.dataValues.process_instance_id; + + task_id = camundaHelper.financialsListOfProcessInstances(processInstanceId); + console.log(task_id) + setTimeout(()=>{ + makercomplete_status = camundaHelper.financialsTaskComplete(task_id); + },1000) + }); + + res.send({'status':200,'message':"success",'data':"No data"}); + logMsg.info("Cheker Completed Success"); + } + catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while Cheker Complete." ,'data': "No data" + }); } + +}; + +exports.camunda = async (req, res) => { + const losid = req.query.losid; + try + { + const losid = "fb37c1e4-271e-11ec-a4f4-42010a800002"; + const cin = "test"; + const user = "test"; + + + instancesid = "33f6a13d-272f-11ec-a4f4-42010a800002"; + taskid = camundaHelper.financialsListOfProcessInstances(instancesid); + res.send({'status':200,'message':"success",'data':"No data"}); + logMsg.info("Cheker Completed Success"); + } + catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while Cheker Complete." ,'data': "No data" + }); } + +}; + +exports.test = (req, res) => { + + try + { + const processInstanceId = "fb2b8cd9-271e-11ec-a4f4-42010a800002"; + + task_id = camundaHelper.financialsListOfProcessInstances(processInstanceId); + + res.send({'status':200,'message':"success",'data':"No data"}); + logMsg.info("Cheker Completed Success"); + } + catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while Cheker Complete." ,'data': "No data" + }); } + +}; + +const doWorkPromise = new Promise((resolve, reject) => { + setTimeout(() => { + resolve([7, 4, 1]) + // reject('Things went wrong!') + }, 2000) +}) + +doWorkPromise.then((result) => { + console.log('Success!', result) +}).catch((error) => { + console.log('Error!', error) +}) + + diff --git a/app/controllers/test.controller.js b/app/controllers/test.controller.js index c072edc..fc0fea4 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -250,7 +250,7 @@ exports.test = (req, res) => { - +// exports.test2 = async (req, res) => { const losid = req.query.losid @@ -263,6 +263,7 @@ exports.test = (req, res) => { // p1(losid).then((losid) => { promise(losid).then((losid) => { + console.log(losid) //pro 42 api call using losid const Pro42Data = [ @@ -332,7 +333,7 @@ exports.test = (req, res) => { }) // end of pro42 data foreach - return ({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message + return ({'losid':losid,'status':201,'message':"success",'data':"No data"}); // success message //end of try catch @@ -342,9 +343,9 @@ exports.test = (req, res) => { //.then((value) => { .then(function(value){ // writeToBody(topic); - console.log(value) + setTimeout(function(){ - console.log(value) + try { if(value.status == 200) @@ -382,7 +383,7 @@ exports.test = (req, res) => { console.log(data) logMsg.info("MenuList api working") Promise.resolve(res.send({'losid':losid,'status':200,'message':"success",'data':data})) - return (data); + // return (data); }); // end of findall EntitiesData }); // end of findall masters datas } // end of starter function if condition diff --git a/app/routes/routes.js b/app/routes/routes.js index d120a1a..f4e0f6b 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -842,8 +842,9 @@ module.exports = app => { * description: success */ router.get("/Historyapi", master.Historyapi); - - router.get("/test2", test.test2); + router.post("/MakerSubmit", master.MakerSubmit); + router.post("/doWorkPromise", master.doWorkPromise); + router.get("/test", master.test); diff --git a/app/services/camunda.helper.js b/app/services/camunda.helper.js index 908fa80..01e7e83 100644 --- a/app/services/camunda.helper.js +++ b/app/services/camunda.helper.js @@ -15,6 +15,7 @@ const URL = process.env.CAMUNDA_URL "user":{"value": user } },"businessKey": businessKey }; + return new Promise((resolve, reject) => { request({ url: start_url, method: "POST", @@ -23,9 +24,10 @@ const URL = process.env.CAMUNDA_URL }, function (error, response, body){ let data = body; instancesid = data.id; - return instancesid; - }); - + resolve(instancesid); + }); + + }); } catch (error) { @@ -33,23 +35,25 @@ const URL = process.env.CAMUNDA_URL } } - function financialsListOfProcessInstances(instancesid) + function financialsListOfProcessInstances(instancesid,req,res) { try { const task_id_url = URL+"task"; const myJSONObject = { "processInstanceIdIn":[instancesid] }; + return new Promise((resolve, reject) => { request({ url: task_id_url, method: "POST", json: true, body: myJSONObject - }, function (error, response, body){ + }, function (error, response, body){ let data = body; - task_id =data[0].id; - return task_id; + task_id = data[0].id; + resolve(task_id); }); - + + }); } catch (error) { @@ -86,13 +90,16 @@ const URL = process.env.CAMUNDA_URL try { const form_variable_url = URL+"task/"+taskid+"/form-variables"; + return new Promise((resolve, reject) => { request({ url: form_variable_url, method: "GET" }, function (error, response, body){ - return body; - }); + resolve(body); + }) + + }); } catch (error)