Files
WrenchBoardBannersMicro/service/banners.js
T
CHIEFSOFT\ameye c5c7ae3510 family banner
2024-08-03 17:53:33 -04:00

394 lines
16 KiB
JavaScript

'use strict';
const request = require('request');
const db = require('../app/db')
const logger = require('../app/logger');
var banners = {
getfamilybanners: function (req, res, next) {
//console.log("REQ---->",req.body.uid);
var data = {
"uid": req.body.uid,
"member_id": req.body.member_id,
"limit": (req.body.limit != null && req.body.limit !== "") ? req.body.limit : 20,
"sessionid": req.body.sessionid,
"page": req.body.page
};
console.log("REQ req.body.uid ---->",data);
let Qstring ="";
let Qstring1 ="";
let Qstring2 ="";
let QextraString ="";
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);
// // 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 = {
"pending": {
"banner": {
"image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-start.jpg",
"icon": "bannerimage.icon",
"style": "style1",
"text": "Ready to Start ?",
"description": "Waiting for you to get started",
"action": "pending",
"status": "0"
}
},
"current": {
"banner": {
"image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-active.jpg",
"icon": "bannerimage.icon",
"style": "style2",
"text": "Current Activities",
"description": "Your currently active task",
"action": "mytask",
"status": "0"
}
},
"suggested": {
"banner": {
"image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-suggested.jpg",
"icon": "bannerimage.icon",
"style": "style2",
"text": "Waiting for Parent",
"description": "Waiting for parent to get started",
"action": "parentwaiting",
"status": "0"
}
},
"recommend": {
"banner": {
"image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-recommend.jpg",
"icon": "bannerimage.icon",
"style": "style3",
"text": "Recommend to Parent",
"description": "Send to parent to approve",
"action": "familymarket",
"status": "0"
}
},
"pastdue": {
"banner": {
"image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-pastdue.jpg",
"icon": "bannerimage.icon",
"style": "style5",
"text": "Past Due",
"description": "Ask for more time if past due",
"action": "pastdue",
"status": "0"
}
}
};
// "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"
// }
// },
},
homebanners: function (req, res, next) {
var result=[];
this.RecoCheckOffers(req, res, function(err, result){
logger.info("************************ aaaa");
logger.info(result);
logger.info("************************ bbbb");
});
var result_list =[
{
"title": "Some family accounts are yet to log in.",
"contract": null,
"card_type": "FAMILY_NOLOGIN",
"card_style": null,
"description": "Some family members have not logged in - a little nudge might help.",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "https://www.wrenchboard.com/assets/images/apps/banners/family-login.jpg",
"banner_location": "URL",
"link_path": "acc-family",
"button_text": "Continue",
"short_button_text": "View Now",
"short_title": "Some family accounts are yet to log in",
"short_description": "Help your family member get started.",
"short_style": "short_style"
},
{
"title": "Yo man , you have Coupons to play with",
"contract": null,
"card_type": "COUPONS",
"card_style": null,
"description": "You have received some cash coupons waiting to be redeemed.",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "https://www.wrenchboard.com/assets/images/apps/banners/banner-coupons.jpg",
"banner_location": "URL",
"link_path": "my-coupon",
"button_text": "Continue",
"short_button_text": "Redeem",
"short_title": "Redeem your Cash Coupons!",
"short_description": "You have received some cash coupons waiting to be redeemed.",
"short_style": "short_style lg"
},
{
"title": "Some of your task as owner Need Review now ",
"contract": null,
"card_type": "REVIEWJOB",
"card_style": null,
"description": "Some of your task as owner Need Review now,Some of your task as owner Need Review now, S Need Review now",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "banner-job-due.jpg",
"banner_location": "LOCAL",
"link_path": "my-review-jobs",
"button_text": "View Tasks",
"short_button_text": "Start Review",
"short_title": "Review Ready Tasks",
"short_description": "Some of your jobs are waiting for approval ",
"short_style": "short_style lr"
},
{
"title": "Some of your task as owner of the tasks are due ",
"contract": null,
"card_type": "PASTDUEJOB",
"card_style": null,
"description": "Some of your task as owner of the tasks are due, Some of your task as owner of the tasks are due",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "https://www.wrenchboard.com/assets/images/apps/banners/past-due.jpg",
"banner_location": "URL",
"link_path": "my-pastdue-jobs",
"button_text": "View Tasks",
"short_button_text": "View",
"short_title": "Past Due Tasks",
"short_description": "Some of you task are now past due",
"short_style": "short_style lr"
},
{
"title": "Share WrenchBoard 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"
}
];
let resultItem ={
"result": result_list,
"total_record": 5
}
next(null, resultItem ); // 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
}
});
},
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) {},
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 = banners;