diff --git a/api/controller.js b/api/controller.js index b1267b2..54fb899 100644 --- a/api/controller.js +++ b/api/controller.js @@ -3,6 +3,8 @@ const properties = require('../package.json') const jobs = require('../service/jobs'); const banners = require('../service/banners'); +const family = require('../service/family'); + const logger = require('../app/logger'); var controllers = { @@ -19,8 +21,15 @@ var controllers = { //res.status(200).json({'status': 'OK', 'result_list': result }) }); }, + familyConnectMembers: function (res,req){ + family.familyConnectMembers(req, res, function(err, dist) { + if (err) { + res.send(err); + } + res.json(dist); + }); + }, getHomeBanners: function(req, res) { - //homebanners banners.homebanners(req, res, function(err, dist) { if (err) { res.send(err); diff --git a/api/routes.js b/api/routes.js index 8c0902a..0740072 100644 --- a/api/routes.js +++ b/api/routes.js @@ -9,4 +9,6 @@ module.exports = function(app) { app.route('/homebanners') .get(controller.getHomeBanners); + app.route('/familyConnectMembers') + .get(controller.familyConnectMembers); }; \ No newline at end of file diff --git a/service/banners.js b/service/banners.js index df69510..736bb80 100644 --- a/service/banners.js +++ b/service/banners.js @@ -15,26 +15,110 @@ var banners = { "sessionid": req.body.sessionid, "page": req.body.page }; - let Qstring =""; // "SELECT uid,id,username FROM members LIMIT 10"; + console.log("REQ req.body.uid ---->",data); + let Qstring =""; + let Qstring1 =""; + let Qstring2 =""; let QextraString =""; - if ( req.body.uid != null && req.body.uid !== ""){ - QextraString= " AND j.country IN (SELECT c.country FROM members_wallet w " + - " LEFT JOIN currency c ON c.code =w.currency " + - " LEFT JOIN members m ON m.id = w.member_id " + - " WHERE m.uid = '"+req.body.uid+"' )"; - } + let bannerCards = {}; + let total_past_client_due = -1; + let total_active_client_job = -1; + + // WHO IS THIS + let client_id = 0 ; + Qstring = " SELECT id AS client_id FROM members WHERE uid = '"+data.uid+"' AND id = " +data.member_id; + logger.info(Qstring); + db.query(Qstring, function (err, result) { + try { + if (err) throw err; + logger.info("client_id result.rows ==> ",result.rows); + client_id = result.rows[0]["client_id"]; + logger.info("client_id AAA ==> ",client_id); + // we must have client_id to contibnue + var reqClinet = { + "uid": req.body.uid, + "client_id": req.body.member_id, + }; + + this.RecoCheckActive=( reqClinet,r2,r3)=>{ + + } + + Qstring1 = " SELECT count(id) AS total_active_jobs FROM members_jobs_contract " + + " WHERE client_id = "+client_id+" AND status =1 AND delivery_date > now() "; + logger.info(Qstring1); + db.query(Qstring1, function (err, result) { + try { + if (err) throw err; + total_active_client_job=0; + total_active_client_job = result.rows[0]["total_active_jobs"]; + logger.info("total_active_client_job** ==> ",total_active_client_job); + if (total_active_client_job) bannerArray.current.banner.status = 1; + } catch (e) { + logger.info("Error on Active Jobs =>", e.message); + } + }); + logger.info("total_active_client_job ==> ",total_active_client_job); + + + Qstring2 = " SELECT count(id) AS total_past_due FROM members_jobs_contract " + + " WHERE client_id = "+client_id+" AND status =1 AND delivery_date < now() "; + logger.info(Qstring2); + db.query(Qstring2, function (err, result) { + try { + if (err) throw err; + total_past_client_due=0; + total_past_client_due = result.rows[0]["total_past_due"]; + if (total_past_client_due) bannerArray.pastdue.banner.status = 1; + } catch (e) { + logger.info("Error on past due =>", e.message); + } + }); + logger.info("total_past_client_due ==> ",total_past_client_due); + + + + + bannerArray.current.banner.status = 1; + + if( total_past_client_due >=0 && + total_active_client_job >=0 ){ + logger.info("RETURN ABOUT TO ==> ************** "); + let resultItem ={ + "result": bannerArray, + "total_record": 4 + } + next(null, resultItem ); // pass control to the next handler + } + + + + + + // end of we have client id + } catch (e) { + logger.info("Error on Client Id =>", e.message); + } + }); + logger.info("client_id ==> ",client_id); + //*********** + + // next(null, { + // "result": [], + // "total_record": 0 + // } ); // pass control to the next handler + + + + + + + // logger.info(" bannerArray.pending ==> ", bannerArray["pending"]); + + // bannerCards.push({"pending" : bannerArray.pending }); + //bannerCards.push(bannerArray.current); + - Qstring = " SELECT j.title,j.description,m.id AS job_id,m.expire,m.job_description,j.price, " + - " m.offer_code,j.timeline_days, to_char(m.expire, 'Dy Mon dd, yyyy HH:MI AM') AS expire2," + - " m.uid AS offer_uid,j.uid AS job_uid,m.added::date AS offer_added,j.country AS job_country, " + - " c.code AS currency_code, c.description AS currency_description,j.country, j.category " + - " FROM members_jobs_offer m " + - " LEFT JOIN members_jobs j ON j.id=m.job_id " + - " LEFT JOIN currency c ON c.country=j.country " + - " WHERE m.status = 1 AND m.client_id=0 " + - " AND m.expire IS NOT NULL " + - " AND m.public_view = 1 AND m.expire> now() AND j.status = 1 " + QextraString + - " ORDER BY m.expire DESC LIMIT "+ data.limit; // // logger.info(Qstring); // db.query(Qstring, function (err, result) { @@ -61,7 +145,8 @@ var banners = { "style": "style1", "text": "Ready to Start ?", "description": "Waiting for you to get started", - "action": "pending" + "action": "pending", + "status": "0" } }, "current": { @@ -71,7 +156,8 @@ var banners = { "style": "style2", "text": "Current Activities", "description": "Your currently active task", - "action": "mytask" + "action": "mytask", + "status": "0" } }, "suggested": { @@ -81,7 +167,8 @@ var banners = { "style": "style2", "text": "Waiting for Parent", "description": "Waiting for parent to get started", - "action": "suggested" + "action": "parentwaiting", + "status": "0" } }, "recommend": { @@ -91,7 +178,8 @@ var banners = { "style": "style3", "text": "Recommend to Parent", "description": "Send to parent to approve", - "action": "familymarket" + "action": "familymarket", + "status": "0" } }, "pastdue": { @@ -101,7 +189,8 @@ var banners = { "style": "style5", "text": "Past Due", "description": "Ask for more time if past due", - "action": "pastdue" + "action": "pastdue", + "status": "0" } } }; @@ -116,12 +205,7 @@ var banners = { // "action": "thisaction" // } // }, - - let resultItem ={ - "result": bannerArray, - "total_record": 4 - } - next(null, resultItem ); // pass control to the next handler + }, homebanners: function (req, res, next) { @@ -274,15 +358,36 @@ var result=[]; }); }, + async RecoCheckActive (req, res, next) { + let total_active_client_job=0; + let Qstring = " SELECT count(id) AS total_active_jobs FROM members_jobs_contract " + + " WHERE client_id = "+req.client_id+" AND status =1 AND delivery_date > now() "; + logger.info(Qstring); + db.query(Qstring, function (err, result) { + try { + if (err) throw err; + total_active_client_job = result.rows[0]["total_active_jobs"]; + logger.info("total_active_client_job** ==> ",total_active_client_job); + let resultItem ={ + "total_active_client_job": total_active_client_job + } + next(null, resultItem); // pass control to the next handler + + } catch (e) { + logger.info("Error on Active Jobs =>", e.message); + } + }); + logger.info("total_active_client_job ==> ",total_active_client_job); + + }, RecoCheckFamilyLogin : function (req, res, next) {}, RecoCheckFamilyCount : function (req, res, next) {}, - RecoCheckFamilyCount : function (req, res, next) {}, RecoCheckCoupons : function (req, res, next) {}, RecoCheckTaskDue : function (req, res, next) {}, RecoCheckTaskReview : function (req, res, next) {}, RecoCheckBlog : function (req, res, next) {}, RecoOffersInterest : function (req, res, next) {}, RecoReferAFreind : function (req, res, next) {}, - RecoPendingInterestCount : function (req, res, next) {} + RecoPendingInterestCount : function (req, res, next) {}, }; module.exports = banners; diff --git a/service/family.js b/service/family.js new file mode 100644 index 0000000..b815515 --- /dev/null +++ b/service/family.js @@ -0,0 +1,41 @@ +'use strict'; + +const request = require('request'); +const db = require('../app/db') +const logger = require('../app/logger'); + +var family = { + familyConnectMembers: function (req, res, next) { + + //console.log("REQ---->",req.body.uid); + var data = { + "member_id": req.body.member_id, + "family_uid": req.body.family_uid + }; + let Qstring = " SELECT member_id FROM members_family WHERE UID ='"+data.family_uid+"'"; + // logger.info(Qstring); + db.query(Qstring, function (err, result) { + try { + if (err) throw err; + console.log("FAMILY row id",result.rows); + + let QstringFamily = " SELECT * FROM members_family WHERE member_id =1"; + db.query(QstringFamily, function (err, result) { + + if (err) throw err; + console.log(result.rows); + + let resultItem ={ + "result": result.rows, + "total_record": result.rowCount + } + // logger.info(result); + next(null, resultItem); // pass control to the next handler + }); + } catch (e) { + next(e.message, null); // pass control to the next handler + } + }); + } +}; +module.exports = family;