diff --git a/api/controller.js b/api/controller.js index b1db098..501c1a5 100644 --- a/api/controller.js +++ b/api/controller.js @@ -1,34 +1,36 @@ 'use strict'; const properties = require('../package.json') -const jobs = require('../service/jobs'); const redeem = require('../service/redeem'); +const wallets = require('../service/wallets'); const logger = require('../app/logger'); var controllers = { getFamilyBanners: function(req, res) { - redeem.getfamilybanners(req, res, function(err, result) { - // logger.info(result); - /* - "status": "OK", - "total_record": 1, - "internal_return": 0, - "result_list" - */ + redeem.getredeemoptions(req, res, function(err, result) { res.status(200).json({'status': 'OK', 'internal_return': 0, 'result_list': result.result,'total_record': result.total_record }) - //res.status(200).json({'status': 'OK', 'result_list': result }) }); }, - getHomeBanners: function(req, res) { - //homebanners - redeem.homebanners(req, res, function(err, dist) { + + getUsersWallets: function(req, res) { + wallets.getuserwallet(req, res, function(err, dist) { if (err) { res.send(err); } - res.json(dist); + // res.json(dist); + res.status(200).json({'status': 'OK', 'internal_return': 0, 'result_list': dist.result,'total_record': dist.total_record }) }); }, + + getUsersEscrows: function(req, res) { + wallets.getescrows(req, res, function(err, dist) { + if (err) { + res.send(err); + } + // res.json(dist); + res.status(200).json({'status': 'OK', 'internal_return': 0, 'result_list': dist.result,'total_record': dist.total_record }) + }); + }, }; module.exports = controllers; - diff --git a/api/routes.js b/api/routes.js index 29e21b5..4f64c1b 100644 --- a/api/routes.js +++ b/api/routes.js @@ -6,7 +6,10 @@ module.exports = function(app) { app.route('/redeemoptions') .get(controller.getFamilyBanners); - app.route('/homebanners') - .get(controller.getHomeBanners); + app.route('/getwallets') + .get(controller.getUsersWallets); + + app.route('/getescrows') + .get(controller.getUsersEscrows); }; \ No newline at end of file diff --git a/service/redeem.js b/service/redeem.js index 26d8dc7..700346c 100644 --- a/service/redeem.js +++ b/service/redeem.js @@ -5,7 +5,7 @@ const db = require('../app/db') const logger = require('../app/logger'); var redeem = { - getfamilybanners: function (req, res, next) { + getredeemoptions: function (req, res, next) { //console.log("REQ---->",req.body.uid); var data = { @@ -15,49 +15,7 @@ var redeem = { "sessionid": req.body.sessionid, "page": req.body.page }; - let Qstring =""; // "SELECT uid,id,username FROM members LIMIT 10"; - 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+"' )"; - } - 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) { - // try { - // if (err) throw err; - // let resultItem ={ - // "result": result.rows, - // "total_record": result.rowCount - // } - // // logger.info(result); - // next(null, resultItem); // pass control to the next handler - // // next(null, result.rows); // pass control to the next handler - // } catch (e) { - // next(e.message, null); // pass control to the next handler - // } -/* - - - - -*/ - - // }); var bannerArray = { "thiskey01": { "banner": { @@ -130,26 +88,19 @@ var redeem = { }, } }; - - // "another1task": { - // "banner": { - // "image": "https://www.wrenchboard.com/assets/images/apps/banners/recommend-banner.jpg", - // "icon": "bannerimage.icon", - // "style": "style4", - // "text": "Dummy for now", - // "description": "dummy dummy dummy", - // "action": "thisaction" - // } - // }, let resultItem ={ "result": bannerArray, - "total_record": 4 + "total_record": 7 } next(null, resultItem ); // pass control to the next handler }, homebanners: function (req, res, next) { + +//SELECT w.amount,c.*,w.amount AS current_balance,c.country,w.transfer_limit,w.uid AS wallet_uid FROM members_wallet w LEFT JOIN currency c ON c.code=w.currency WHERE w.member_id = 1 ORDER BY c.lorder DESC + + var result=[]; this.RecoCheckOffers(req, res, function(err, result){ diff --git a/service/wallets.js b/service/wallets.js new file mode 100644 index 0000000..4876b2d --- /dev/null +++ b/service/wallets.js @@ -0,0 +1,132 @@ +'use strict'; + +const request = require('request'); +const db = require('../app/db') +const logger = require('../app/logger'); + +var wallets = { + getuserwallet: function (req, res, next) { + + //console.log("REQ---->",req.body.uid); + var data = { + "uid": req.body.uid, + "member_id": req.body.member_id, + "sessionid": req.body.sessionid, + }; + let Qstring = ""; + Qstring = "SELECT w.amount,c.*,w.amount AS current_balance,c.country," + + "w.transfer_limit,w.uid AS wallet_uid, 0 AS escrow " + + "FROM members_wallet w " + + "LEFT JOIN currency c ON c.code=w.currency " + + "LEFT JOIN members m ON m.id = w.member_id " + + "WHERE w.member_id = " + data.member_id + + " AND m.uid='" + data.uid + "' ORDER BY c.lorder DESC "; + logger.info(Qstring); + db.query(Qstring, function (err, result) { + try { + if (err) throw err; + let resultItem = { + "result": result.rows, + "total_record": result.rowCount + } + next(null, resultItem); // pass control to the next handler + } catch (e) { + next(e.message, null); // pass control to the next handler + } + + + }); + }, + getescrows: function (req, res, next) { + var result = []; + + // this.RecoCheckOffers(req, res, function (err, result) { + + var data = { + "uid": req.body.uid, + "member_id": req.body.member_id, + "sessionid": req.body.sessionid, + }; + + // + + var data = { + "uid": req.body.uid, + "member_id": req.body.member_id, + "sessionid": req.body.sessionid, + }; + let Qstring = "SELECT sum(amount) AS escrow,currency " + + " FROM members_payments "+ + " WHERE code ='OFDPS' AND member_id = " + data.member_id + + " AND confirmation IS NOT NULL "+ + " AND flags = 4 GROUP BY currency"; + logger.info(Qstring); + db.query(Qstring, function (err, result) { + try { + if (err) throw err; + let resultItem = { + "result": result.rows, + "total_record": result.rowCount + } + next(null, resultItem); // pass control to the next handler + } catch (e) { + next(e.message, null); // pass control to the next handler + } + + }); + // }); + + }, + RecoCheckOffers: function (req, res, next) { + let Qstring = "SELECT * FROM members_jobs_offer WHERE expire > now() " + + "AND status = 1 AND client_id > 0 AND client_id =" + req.body.member_id; + logger.info(Qstring); + db.query(Qstring, function (err, result) { + try { + if (err) throw err; + let resultItem = { + "result": + [ + { + "title": "Share RecoCheckOffers with a friend.", + "contract": null, + "card_type": "INVITE", + "card_style": null, + "description": "Show WrenchBoard to a friend and earn free coupons. Get started.", + "blog_id": "0", + "card_icon": "icon1", + "offer_id": "0", + "banner": "banner-refer.jpg", + "banner_location": "LOCAL", + "link_path": "referral", + "button_text": "Continue", + "short_button_text": "View now", + "short_title": "Invite a Friend - get Rewards", + "short_description": "Share WrenchBoard with a friend.", + "short_style": "short_style by" + } + ] + + , + "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 + } + }); + + }, + 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) { } +}; +module.exports = wallets;