commit 1f2d886553555f7a8dc5dc4301935543a1d32692 Author: CHIEFSOFT\ameye Date: Sat Dec 21 09:55:29 2024 -0500 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74cfa80 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules +*.log +config.json +.queues +*.txt +docs +.env diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/WrenchBoardBanners.iml b/.idea/WrenchBoardBanners.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/WrenchBoardBanners.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..03d9549 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6d60b87 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..f324872 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24c04a6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:erbium + +# Create app directory +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +# Install app dependencies +COPY package.json /usr/src/app/ +RUN npm install + +COPY . /usr/src/app + +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/api/controller.js b/api/controller.js new file mode 100644 index 0000000..3d2391f --- /dev/null +++ b/api/controller.js @@ -0,0 +1,75 @@ +'use strict'; + +const properties = require('../package.json') +const redeem = require('../service/redeem'); +const wallets = require('../service/wallets'); +const ebroker = require('../service/ebroker'); + +const logger = require('../app/logger'); + +var controllers = { + getFamilyBanners: function(req, res) { + 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 }) + }); + }, + + getUsersWallets: function(req, res) { + wallets.getuserwallet(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 }) + }); + }, + + flutterOkHook: function(req, res) { + ebroker.eventPublish(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 }) + }); + }, + siteSettings: function(req, res) { + wallets.siteSettings(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 }) + }); + }, + eventSendMoney: function(req, res) { + ebroker.eventSendMoney(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 }) + }); + }, + getUsersKidsWallets: function(req, res) { + wallets.getuserkidswallet(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 }) + }); + }, + + 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 new file mode 100644 index 0000000..1dd22a9 --- /dev/null +++ b/api/routes.js @@ -0,0 +1,27 @@ +'use strict'; + +const controller = require('./controller'); + +module.exports = function(app) { + app.route('/redeemoptions') + .get(controller.getFamilyBanners); + + app.route('/getwallets') + .get(controller.getUsersWallets); + + app.route('/getkidswallets') + .get(controller.getUsersKidsWallets); + + app.route('/getescrows') + .get(controller.getUsersEscrows); + + app.route('/flutterOkHook') + .post(controller.flutterOkHook); + + app.route('/eventSendMoney') + .post(controller.eventSendMoney); + + app.route('/settings') + .get(controller.siteSettings); + +}; \ No newline at end of file diff --git a/app/db.js b/app/db.js new file mode 100644 index 0000000..d08ddec --- /dev/null +++ b/app/db.js @@ -0,0 +1,57 @@ +/** + * @file + * Configures the database connection + */ + +const { Pool, Client } = require('pg'); +const url = require('url'); +const logger = require('./logger'); +//const connectionString = 'postgresql://wrenchboard:wrenchboard@10.10.10.23:5432/wrenchboard'; +const connectionString = process.env.POSTGRE_URL.replace(/'/g, ''); +const params = url.parse(connectionString); +const auth = params.auth.split(':'); +const config = { + user: auth[0], + password: auth[1], + host: params.hostname, + port: params.port, + database: params.pathname.split('/')[1], + ssl: false +}; + +const postgres = new Pool(config); + +postgres.on('connect', client => { + logger.info('Connected to Database'); +}); + +postgres.on('acquire', client => { + logger.info('Client is checked out from the DB connection pool'); +}); + +postgres.on('remove', client => { + logger.info('Client is closed & removed from the DB connection pool'); +}); + +postgres.on('error', (err, client) => { + logger.error(err); +}); + +// Connect to PostgreSQL +postgres.connect((err, client, release) => { + logger.info(connectionString); + if (err) { + logger.error('Error acquiring client', err.stack); + return null; + } + client.query('SELECT NOW()', (err, result) => { + release(); + if (err) { + logger.error('Error executing query', err.stack); + return nul; + } + logger.info(result.rows); + }); +}); + +module.exports = postgres; \ No newline at end of file diff --git a/app/index.js b/app/index.js new file mode 100644 index 0000000..b659952 --- /dev/null +++ b/app/index.js @@ -0,0 +1,10 @@ +/** + * @file + * Set up the app + */ +var _ = require('underscore'); +var db = require('./db'); + +module.exports = function () { + db(); +}; \ No newline at end of file diff --git a/app/kconfig.js b/app/kconfig.js new file mode 100644 index 0000000..7d92f2e --- /dev/null +++ b/app/kconfig.js @@ -0,0 +1,55 @@ +// import { Kafka } from "kafkajs"; +const dotenv = require('dotenv'); +const env = dotenv.config(); +//console.log("ENVVVVV ", env); + +const {Kafka} = require('kafkajs'); +const kafkaBroker1 = process.env.WRENCHJOB_KAFKA_BROKER01; + +console.log("kafkaBroker1", kafkaBroker1); + +const kafka = new Kafka({ + clientId: "wallet-kafka", + brokers: [kafkaBroker1], +}); +class KafkaConfig { + + constructor() { + console.log("kafkaBroker1 ******** ", kafkaBroker1); + this.producer = kafka.producer(); + this.consumer = kafka.consumer({ groupId: "test-group" }); + } + + async produce(topic, messages) { + try { + console.log("kafkaBroker1 ######### ", kafkaBroker1); + await this.producer.connect(); + await this.producer.send({ + topic: topic, + messages: messages, + }); + } catch (error) { + console.error(error); + } finally { + await this.producer.disconnect(); + } + } + + async consume(topic, callback) { + try { + await this.consumer.connect(); + await this.consumer.subscribe({ topic: topic, fromBeginning: true }); + await this.consumer.run({ + eachMessage: async ({ topic, partition, message }) => { + const value = message.value.toString(); + callback(value); + }, + }); + } catch (error) { + console.error(error); + } + } +} + +module.exports = KafkaConfig; +//export default KafkaConfig; \ No newline at end of file diff --git a/app/logger.js b/app/logger.js new file mode 100644 index 0000000..5b052f6 --- /dev/null +++ b/app/logger.js @@ -0,0 +1,61 @@ +/** + * @file + * Defines logger for the microservice + */ + +var winston = require('winston'); +var Papertrail = require('winston-papertrail').Papertrail; +var serviceIdentifier = require('../package.json').name; + +var host = process.env.LOG_SERVICE_HOST; +var port = process.env.LOG_SERVICE_PORT; + +/** + * Class to provide logging facilities for the microservice + * @constructor + */ + +var Logger = function () { + + // Try to route logs to third party service + if (host && port) { + // Define our transport + var transport = new Papertrail({ + levels: { + debug: 0, + info: 1, + error: 3 + }, + colors: { + debug: 'blue', + info: 'green', + error: 'red' + }, + host, + port, + json: true, + colorize: true, + logFormat: (level, message) => { + return `[${serviceIdentifier}] ${level} : ${message}`; + } + }); + + // Handle exceptions + transport.exceptionsLevel = 'error'; + winston.handleExceptions(transport); + } + + this.info = winston.info; + this.error = winston.error; + this.debug = winston.debug; +}; + +module.exports = new Logger(); + + +/** + * @typedef {Object} Logger + * @property {function} info - Log in level `info` + * @property {function} error - Log in level `error` + * @property {function} debug - Log in level `debug` + */ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a284361 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3' +services: + merms-event-manager: + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + # image: registry.chiefsoft.net/flutterwave-transfer-micro:latest + volumes: + - ./:/app + - '/app/node_modules' + ports: + - 5006:3000 + extra_hosts: + - api.mermsemr.com:10.10.33.15 + - devapi.mermsemr.com:10.10.33.15 + - dev-socket.mermsemr.com:10.10.33.15 + - socket.mermsemr.com:10.10.33.15 + - dev-media.mermsemr.com:10.10.33.15 + - media.mermsemr.com:10.10.33.15 + environment: + - PORT=${WRENCHJOB_PORT} + - POSTGRE_URL=${WRENCHJOB_POSTGRE_URL} +volumes: + src: \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..15f6592 --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "merms-event-manage", + "version": "0.0.1", + "description": "merms-event-manage", + "main": "server.js", + "scripts": { + "generate-docs": "jsdoc ./api/*.js ./api/**/*.js ./app/*.js ./app/**/*.js ./service/*.js ./service/**/*.js -d docs", + "lint": "eslint ./ --ext .js", + "start": "node server.js", + "start:dev": "nodemon server.js", + "test": "npm run lint" + }, + "author": "WrenchBoard Support ", + "dependencies": { + "axios": "^0.24.0", + "body-parser": "^1.19.0", + "cors": "^2.8.5", + "dotenv": "^16.4.5", + "cookie-parser": "^1.4.6", + "express": "^4.17.1", + "kafkajs": "^2.2.4", + "openapi-types": "^10.0.0", + "pg": "8.7.1", + "pg-pool": "^3.5.1", + "request": "^2.88.2", + "swagger-autogen": "^2.17.2", + "swagger-jsdoc": "^6.1.0", + "swagger-ui-express": "^4.3.0", + "socket.io-client": "^4.8.1", + "underscore": "^1.8.3", + "url": "^0.11.0", + "winston": "^2.3.1", + "winston-papertrail": "^1.0.4" + }, + "devDependencies": { + "eslint": "^1.10.3", + "jsdoc": "^3.4.3", + "nodemon": "^1.11.0" + } + } \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..7935f24 --- /dev/null +++ b/server.js @@ -0,0 +1,44 @@ +const express = require('express'); +const cors = require('cors'); +const cookieParser = require('cookie-parser'); +const bodyParser = require('body-parser'); +const logger = require('./app/logger'); +const port = process.env.PORT || 3000; +const KafkaConfig = require("./app/kconfig"); +const io = require("socket.io-client"); + +const app = express(); + +// create application/json parser +var jsonParser = bodyParser.json(); // express.json(); + +// create application/x-www-form-urlencoded parser +var urlencodedParser = bodyParser.urlencoded({ extended: false }); // express.bodyParser({extended: true}); + +app.use(urlencodedParser); +app.use(jsonParser); +app.use(cors()); +app.use(cookieParser()); + +// parse application/vnd.api+json as json +app.use(bodyParser.json({ type: 'application/vnd.api+json' })) + +// const socket = io.connect(process.env.SOCKET_URL); +const socket = io.connect("http://10.0.0.32:5005"); +// + +// respond with "hello world" when a GET request is made to the homepage +app.get('/broadcast/general', (req, res) => { + const room = 'merms_global_events'; + const message_action = 'refresh_all_actions'; + socket.emit("join_room", room); + socket.emit("send_message", { message_action , room }); + res.send('hello world') +}) + +const routes = require('./api/routes'); +routes(app); + +app.listen(port, "0.0.0.0", function() { + logger.info('***** Server started on port: ' + port + ' *****'); +}); diff --git a/service/banners.js b/service/banners.js new file mode 100644 index 0000000..596e32f --- /dev/null +++ b/service/banners.js @@ -0,0 +1,323 @@ +'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 + }; + 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": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-card.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + }, + "thiskey02": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-amazon.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "Send your balance to Amazon Digital Card", + "description": "Some descriptio.n of this item, ", + "action": "thiskey" + }, + }, + "thiskey03": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-apple.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + }, + "thiskey04": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-plays.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + }, + "thiskey05": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-xbox.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + }, + "thiskey06": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-start.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + }, + "thiskey07": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-start.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + }, + "thiskey08": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-start.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey" + }, + } + }; + + // "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 + } + next(null, resultItem ); // pass control to the next handler + + }, + 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 + } + }); + + }, + 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 = banners; diff --git a/service/ebroker.js b/service/ebroker.js new file mode 100644 index 0000000..2c137f7 --- /dev/null +++ b/service/ebroker.js @@ -0,0 +1,74 @@ +'use strict'; + +const request = require('request'); +const db = require('../app/db') +const logger = require('../app/logger'); +const KafkaConfig = require("../app/kconfig"); + +var ebroker = { + eventPublish: function (req, res, next) { + + try { + const { message } = req.body; + console.log('THIS-> req.body -> ', req.body); + const kafkaConfig = new KafkaConfig(); + const messages = [{ key: "key1", value: message }]; + // const messages = [{ key: "key1", value: "ameye olusesan" }]; + kafkaConfig.produce("FLUTTER_PAYMENT_RECEIVED", messages).then(r =>{ + console.log('THIS->RET-> ',r); + } ); + + res.status(200).json({ + status: "Ok!", + message: "Message successfully send!", + }); + } catch (error) { + console.log(error); + } + + let resultItem ={ + "result": [], + "total_record": 0 + } + next(null, resultItem ); // pass control to the next handler + }, + eventSendMoney: function (req, res, next) { + + try { + const { message } = req.body; + console.log('THIS-> req.body -> ', req.body); + const kafkaConfig = new KafkaConfig(); + const messages = [{ key: "send", value: JSON.stringify(message) }]; + kafkaConfig.produce("SENDMONEY_RECEIVED", messages).then(r =>{ + console.log('THIS->RET-> ',r); + } ); + + res.status(200).json({ + status: "Ok!", + message: "Message successfully send!", + }); + } catch (error) { + console.log(error); + } + + let resultItem ={ + "result": [], + "total_record": 0 + } + next(null, resultItem ); // pass control to the next handler + }, + eventConsumer: 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 + }; + + + } +}; +module.exports = ebroker; diff --git a/service/jobs.js b/service/jobs.js new file mode 100644 index 0000000..6e39573 --- /dev/null +++ b/service/jobs.js @@ -0,0 +1,56 @@ +'use strict'; + +const request = require('request'); +const db = require('../app/db') +const logger = require('../app/logger'); + +var jobs = { + getmarketjobs: 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 + }; + 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 + } + }); + } +}; +module.exports = jobs; diff --git a/service/redeem.js b/service/redeem.js new file mode 100644 index 0000000..711bdfd --- /dev/null +++ b/service/redeem.js @@ -0,0 +1,286 @@ +'use strict'; + +const request = require('request'); +const db = require('../app/db') +const logger = require('../app/logger'); + +var redeem = { + getredeemoptions: 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 + // }; + + var data = { + "uid": req.query.uid, + "member_id": req.query.member_id, + "sessionid": req.query.sessionid, + "limit": (req.query.limit != null && req.query.limit !== "") ? req.query.limit : 20, + "page": req.query.page + }; + + var bannerArray = { + "thiskey01": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-card.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "Send balance to your debit card", + "description": "Some description of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "FULL" + }, + }, + "thiskey02": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-amazon.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "Send your balance to Amazon Digital Card", + "description": "Some descriptio.n of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "FULL" + }, + }, + "thiskey03": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-apple.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "Send Balance to your Apple Card", + "description": "Some description of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "" + }, + }, + "thiskey04": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-plays.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "Use your credit on PlayStations", + "description": "Some description of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "FULL" + }, + }, + "thiskey05": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/redeem/rex-xbox.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "FULL" + }, + }, + "thiskey06": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-start.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "" + }, + }, + "thiskey07": { + "banner": { + "image": "https://www.wrenchboard.com/assets/images/apps/banners/kids/banner-start.jpg", + "icon": "bannerimage.icon", + "style": "style1", + "text": "This is the title text?", + "description": "Some description of this item, ", + "action": "thiskey", + "feature_token" : "", + "open_type" : "" + }, + } + }; + + let resultItem ={ + "result": bannerArray, + "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){ + 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 + } + }); + + }, + 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 = redeem; diff --git a/service/wallets.js b/service/wallets.js new file mode 100644 index 0000000..3095cfc --- /dev/null +++ b/service/wallets.js @@ -0,0 +1,187 @@ +'use strict'; + +const request = require('request'); +const db = require('../app/db') +const logger = require('../app/logger'); + +var wallets = { + getuserwallet: function (req, res, next) { + logger.info("getuserwallet: function (req, res, next)"); + //console.log("REQ---->",req.body.uid); + logger.info(req.query); + var data = { + "uid": req.query.uid, + "member_id": req.query.member_id, + "sessionid": req.query.sessionid, + }; + let Qstring = ""; + Qstring = "SELECT w.amount,c.*,w.amount AS current_balance,c.country,c.banner, m.country AS owner_country, " + + " w.transfer_limit,w.uid AS wallet_uid, 0 AS escrow,w.brand,w.card_last4 " + + "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 + } + }); + }, + siteSettings: function (req, res, next) { + logger.info("siteSettings: function (req, res, next)"); + let Qstring = ""; + Qstring = "SELECT * FROM settings"; + 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 + } + }); + }, + getuserkidswallet: function (req, res, next) { + logger.info("getuserkidswallet: function (req, res, next)"); + //console.log("REQ---->",req.body.uid); + logger.info(req.query); + var data = { + "uid": req.query.uid, + "member_id": req.query.member_id, + "family_uid": req.query.family_uid, + "sessionid": req.query.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 ,w.brand,w.card_last4 " + + "FROM members_wallet w " + + "LEFT JOIN members_family f ON w.member_id = f.family_member_id " + + "LEFT JOIN currency c ON c.code=w.currency " + + " LEFT JOIN members m ON m.id = f.member_id " + + "WHERE f.uid = '" + data.family_uid + "' " + + "AND f.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) { + logger.info("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) { + logger.info("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;