first commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
WRENCHJOB_PORT=3000
|
||||
WRENCHJOB_POSTGRE_URL='postgresql://wrenchboard:wrenchboard@10.20.30.60:5432/wrenchboard'
|
||||
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
*.log
|
||||
config.json
|
||||
.queues
|
||||
*.txt
|
||||
docs
|
||||
+13
@@ -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" ]
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const properties = require('../package.json')
|
||||
const jobs = require('../service/jobs');
|
||||
const banners = require('../service/banners');
|
||||
const logger = require('../app/logger');
|
||||
|
||||
var controllers = {
|
||||
getFamilyBanners: function(req, res) {
|
||||
banners.getfamilybanners(req, res, function(err, result) {
|
||||
// logger.info(result);
|
||||
/*
|
||||
"status": "OK",
|
||||
"total_record": 1,
|
||||
"internal_return": 0,
|
||||
"result_list"
|
||||
*/
|
||||
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 })
|
||||
});
|
||||
},
|
||||
getStatus: function(req, res) {
|
||||
banners.get(req, res, function(err, dist) {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
}
|
||||
res.json(dist);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = controllers;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const controller = require('./controller');
|
||||
|
||||
module.exports = function(app) {
|
||||
app.route('/familybanners')
|
||||
.get(controller.getFamilyBanners);
|
||||
|
||||
app.route('/marketjob3s/:id')
|
||||
.get(controller.getStatus);
|
||||
|
||||
};
|
||||
@@ -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;
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @file
|
||||
* Set up the app
|
||||
*/
|
||||
var _ = require('underscore');
|
||||
var db = require('./db');
|
||||
|
||||
module.exports = function () {
|
||||
db();
|
||||
};
|
||||
@@ -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`
|
||||
*/
|
||||
@@ -0,0 +1,18 @@
|
||||
version: '3'
|
||||
services:
|
||||
wrenchboard-banners-micro:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
restart: unless-stopped
|
||||
# image: registry.chiefsoft.net/flutterwave-transfer-micro:latest
|
||||
volumes:
|
||||
- ./:/app
|
||||
- '/app/node_modules'
|
||||
ports:
|
||||
- 3032:3000
|
||||
environment:
|
||||
- PORT=${WRENCHJOB_PORT}
|
||||
- POSTGRE_URL=${WRENCHJOB_POSTGRE_URL}
|
||||
volumes:
|
||||
src:
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "wrenhboard-banners-micro",
|
||||
"version": "0.0.1",
|
||||
"description": "A microservice to handle wrenchboard banners listing",
|
||||
"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 <support@wrenchboard.com>",
|
||||
"dependencies": {
|
||||
"axios": "^0.24.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"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",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
const express = require('express');
|
||||
const logger = require('./app/logger');
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded());
|
||||
|
||||
const routes = require('./api/routes');
|
||||
routes(app);
|
||||
|
||||
app.listen(port, "0.0.0.0", function() {
|
||||
logger.info('***** Server started on port: ' + port + ' *****');
|
||||
});
|
||||
@@ -0,0 +1,106 @@
|
||||
'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 = {
|
||||
"pending": {
|
||||
"banner": {
|
||||
"image": "bannerimage.png",
|
||||
"icon": "bannerimage.icon",
|
||||
"style": "style1",
|
||||
"text": "This is Banner Main text"
|
||||
}
|
||||
},
|
||||
"current": {
|
||||
"banner": {
|
||||
"image": "bannerimage.png",
|
||||
"icon": "bannerimage.icon",
|
||||
"style": "style2",
|
||||
"text": "This is Banner Main text"
|
||||
}
|
||||
},
|
||||
"recommend": {
|
||||
"banner": {
|
||||
"image": "bannerimage.png",
|
||||
"icon": "bannerimage.icon",
|
||||
"style": "style3",
|
||||
"text": "This is Banner Main text"
|
||||
}
|
||||
},
|
||||
"another1task": {
|
||||
"banner": {
|
||||
"image": "bannerimage.png",
|
||||
"icon": "bannerimage.icon",
|
||||
"style": "style4",
|
||||
"text": "This is Banner Main text"
|
||||
}
|
||||
},
|
||||
"pastdue": {
|
||||
"banner": {
|
||||
"image": "bannerimage.png",
|
||||
"icon": "bannerimage.icon",
|
||||
"style": "style5",
|
||||
"text": "This is Banner Main text"
|
||||
}
|
||||
}
|
||||
};
|
||||
let resultItem ={
|
||||
"result": bannerArray,
|
||||
"total_record": 5
|
||||
}
|
||||
next(null, resultItem ); // pass control to the next handler
|
||||
|
||||
}
|
||||
};
|
||||
module.exports = banners;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user