Pre-release tidy up

This commit is contained in:
Martin Donnelly 2016-04-06 17:02:43 +01:00
parent 85ee70f344
commit bb2daacd2b
12 changed files with 61 additions and 212 deletions

21
ecosystem.json Normal file
View File

@ -0,0 +1,21 @@
{
/**
* Application configuration section
* http://pm2.keymetrics.io/docs/usage/application-declaration/
*/
apps : [
// First application
{
name : "Obrand Admin Server",
script : "obrand-server.js",
env: {
COMMON_VARIABLE: "true"
},
env_production : {
NODE_ENV: "production"
}
}
]
}

View File

@ -1,4 +1,3 @@
'use strict';
var db = require('../units/db-connector').dbConnection; var db = require('../units/db-connector').dbConnection;
var dbAccounts = require('../units/db-accounts')(db); var dbAccounts = require('../units/db-accounts')(db);
module.exports = function(app) { module.exports = function(app) {
@ -20,7 +19,6 @@ module.exports = function(app) {
} }
} }
}; };
console.log(response);
res.status(200).send(response); res.status(200).send(response);
}) })
.catch(function(err) { .catch(function(err) {

View File

@ -6,7 +6,7 @@
* *
*/ */
/*jshint node:true*/ /*jshint node:true*/
'use strict';
var db = require('../units/db-connector').dbConnection; var db = require('../units/db-connector').dbConnection;
var dbPages = require('../units/db-pages')(db); var dbPages = require('../units/db-pages')(db);
@ -17,20 +17,17 @@ module.exports = function(app) {
var beaconRouter = express.Router(); var beaconRouter = express.Router();
beaconRouter.get('/', function(req, res) { beaconRouter.get('/', function(req, res) {
'use strict';
var beacon = {}; var beacon = {};
if (req.headers.hasOwnProperty('beacon')) { if (req.headers.hasOwnProperty('beacon')) {
beacon = JSON.parse(req.headers.beacon); beacon = JSON.parse(req.headers.beacon);
logger.debug(beacon);
} }
/* res.send({
beacon: beacon
});*/
logger.info('gettingLatestAddedPage'); logger.info('gettingLatestAddedPage');
dbPages.getLatestAddedPage() dbPages.getLatestAddedPage()
.then((d) => { .then((d) => {
logger.debug(d);
//res.status(407).end();
res.redirect(301, d.fullpath); res.redirect(301, d.fullpath);
}).catch((err)=> { }).catch((err)=> {
console.error(err); console.error(err);

View File

@ -1,5 +1,4 @@
/*jshint node:true*/ /*jshint node:true*/
'use strict';
var db = require('../units/db-connector').dbConnection; var db = require('../units/db-connector').dbConnection;
var dbCompany = require('../units/db-company')(db); var dbCompany = require('../units/db-company')(db);
var $U = require('md-utils'); var $U = require('md-utils');
@ -9,6 +8,7 @@ module.exports = function(app) {
var companiesRouter = express.Router(); var companiesRouter = express.Router();
companiesRouter.get('/:id', function(req, res) { companiesRouter.get('/:id', function(req, res) {
'use strict';
var id = req.params.id; var id = req.params.id;
dbCompany.sqlGetSimpleCompany(id) dbCompany.sqlGetSimpleCompany(id)
.then(function(data) { .then(function(data) {
@ -18,7 +18,6 @@ module.exports = function(app) {
type: 'company', id: id, attributes: $U.reDashObject(data) type: 'company', id: id, attributes: $U.reDashObject(data)
} }
}; };
console.log(response);
res.status(200).send(response); res.status(200).send(response);
}) })
.catch(function(err) { .catch(function(err) {
@ -27,25 +26,9 @@ module.exports = function(app) {
}); });
}); });
companiesRouter.post('/', function(req, res) {
res.status(201).end();
});
companiesRouter.get('/:id', function(req, res) {
res.send({
companies: {
id: req.params.id
}
});
});
companiesRouter.patch('/:id', function(req, res) { companiesRouter.patch('/:id', function(req, res) {
'use strict';
if (/Bearer .+/.test(req.headers.authorization)) { if (/Bearer .+/.test(req.headers.authorization)) {
console.log('Patching: ' + req.params.id);
console.log(req.body.data);
var updateData = $U.unDashObject(req.body.data.attributes); var updateData = $U.unDashObject(req.body.data.attributes);
dbCompany.addNewCompany(updateData) dbCompany.addNewCompany(updateData)
.then(function(d) { .then(function(d) {
@ -71,16 +54,7 @@ module.exports = function(app) {
res.status(204).end(); res.status(204).end();
}); });
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// Npm install --save-dev body-parser
app.use('/api/companies', require('body-parser').json({type: 'application/vnd.api+json'})); app.use('/api/companies', require('body-parser').json({type: 'application/vnd.api+json'}));
// After installing, you need to `use` the body-parser for
// this mock uncommenting the following line:
//
//App.use('/api/companies', require('body-parser').json());
app.use('/api/companies', companiesRouter); app.use('/api/companies', companiesRouter);
}; };

View File

@ -1,10 +1,11 @@
/*jshint node:true*/ /*jshint node:true*/
'use strict';
var db = require('../units/db-connector').dbConnection; var db = require('../units/db-connector').dbConnection;
var dbCompany = require('../units/db-company')(db); var dbCompany = require('../units/db-company')(db);
var dbAccounts = require('../units/db-accounts')(db); var dbAccounts = require('../units/db-accounts')(db);
var $U = require('md-utils'); var $U = require('md-utils');
var events = require('events'); var events = require('events');
// Create an eventEmitter object // Create an eventEmitter object
var eventEmitter = new events.EventEmitter(); var eventEmitter = new events.EventEmitter();
@ -13,7 +14,7 @@ module.exports = function(app) {
var newcompaniesRouter = express.Router(); var newcompaniesRouter = express.Router();
eventEmitter.on('makeMemberOf', (uid, cid) => { eventEmitter.on('makeMemberOf', (uid, cid) => {
console.log('Make ' + uid + ' a member of ' + cid); 'use strict';
dbAccounts.makeMemberOf(uid, cid) dbAccounts.makeMemberOf(uid, cid)
.catch(function(err) { .catch(function(err) {
console.error(err); console.error(err);
@ -27,6 +28,7 @@ module.exports = function(app) {
}); });
newcompaniesRouter.post('/', function(req, res) { newcompaniesRouter.post('/', function(req, res) {
'use strict';
var updateData = $U.unDashObject(req.body.data.attributes); var updateData = $U.unDashObject(req.body.data.attributes);
if (/Bearer .+/.test(req.headers.authorization)) { if (/Bearer .+/.test(req.headers.authorization)) {
dbCompany.addNewCompany(updateData) dbCompany.addNewCompany(updateData)
@ -49,35 +51,7 @@ module.exports = function(app) {
} }
}); });
newcompaniesRouter.get('/:id', function(req, res) {
res.send({
newcompanies: {
id: req.params.id
}
});
});
newcompaniesRouter.put('/:id', function(req, res) {
res.send({
newcompanies: {
id: req.params.id
}
});
});
newcompaniesRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// Npm install --save-dev body-parser
app.use('/api/newcompanies', require('body-parser').json({type: 'application/vnd.api+json'})); app.use('/api/newcompanies', require('body-parser').json({type: 'application/vnd.api+json'}));
// After installing, you need to `use` the body-parser for
// this mock uncommenting the following line:
app.use('/api/newcompanies', newcompaniesRouter); app.use('/api/newcompanies', newcompaniesRouter);
}; };

View File

@ -17,15 +17,11 @@ var templates = {
var exportPath = __dirname + '/../static/'; var exportPath = __dirname + '/../static/';
var eventRenderPage = (page) => {
console.log('+++ eventRenderPage');
doRenderPage(page);
};
var doRenderPage = (page) => { var doRenderPage = (page) => {
console.log('+ doRenderPage');
var compiledhtml, _page = $U.unDashObject(page); var compiledhtml;
var _page = $U.unDashObject(page);
var htmlfile = exportPath + _page.pid + '.html'; var htmlfile = exportPath + _page.pid + '.html';
if (templates.basic.compiled === null) { if (templates.basic.compiled === null) {
@ -35,7 +31,11 @@ var doRenderPage = (page) => {
compiledhtml = templates.basic.compiled(_page); compiledhtml = templates.basic.compiled(_page);
fs.writeFileSync(htmlfile, compiledhtml); fs.writeFileSync(htmlfile, compiledhtml);
console.log('- doRenderPage');
};
var eventRenderPage = (page) => {
doRenderPage(page);
}; };
eventHandler.on('renderPage', eventRenderPage); eventHandler.on('renderPage', eventRenderPage);
@ -46,12 +46,9 @@ module.exports = function(app) {
pagesRouter.get('/', function(req, res) { pagesRouter.get('/', function(req, res) {
console.log(req.query.filter);
dbPages.getFullPageList() dbPages.getFullPageList()
.then(function(data) { .then(function(data) {
// console.log(util.inspect(data));
const response = { const response = {
data: data data: data
}; };
@ -67,8 +64,6 @@ module.exports = function(app) {
pagesRouter.get('/list', function(req, res) { pagesRouter.get('/list', function(req, res) {
dbPages.getPageList() dbPages.getPageList()
.then(function(data) { .then(function(data) {
console.log(util.inspect(data));
res.render('pages', {data: data}); res.render('pages', {data: data});
}).catch((err)=> { }).catch((err)=> {
@ -79,8 +74,6 @@ module.exports = function(app) {
pagesRouter.post('/', function(req, res) { pagesRouter.post('/', function(req, res) {
console.log(util.inspect(req.body.data));
dbPages.addNewPage(req.body.data) dbPages.addNewPage(req.body.data)
.then(function(data) { .then(function(data) {
@ -88,7 +81,6 @@ module.exports = function(app) {
data: data data: data
}; };
console.log('Finalising...');
res.status(200).send(response); res.status(200).send(response);
eventHandler.emit('renderPage', data.attributes); eventHandler.emit('renderPage', data.attributes);
@ -100,7 +92,6 @@ module.exports = function(app) {
}); });
pagesRouter.patch('/', function(req, res) { pagesRouter.patch('/', function(req, res) {
console.log(util.inspect(req.body.data));
dbPages.addNewPage(req.body.data) dbPages.addNewPage(req.body.data)
.then(function(data) { .then(function(data) {
@ -108,8 +99,6 @@ module.exports = function(app) {
let response = { let response = {
data: data data: data
}; };
console.log('Finalising...');
res.status(200).send(response); res.status(200).send(response);
eventHandler.emit('renderPage', data.attributes); eventHandler.emit('renderPage', data.attributes);
@ -128,29 +117,8 @@ module.exports = function(app) {
}); });
}); });
pagesRouter.put('/:id', function(req, res) {
res.send({
pages: {
id: req.params.id
}
});
});
pagesRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// Npm install --save-dev body-parser
app.use('/api/pages', app.use('/api/pages',
require('body-parser').json({type: 'application/vnd.api+json'})); require('body-parser').json({type: 'application/vnd.api+json'}));
// After installing, you need to `use` the body-parser for
// this mock uncommenting the following line:
//
//App.use('/api/pages', require('body-parser').json());
app.use('/api/pages', pagesRouter); app.use('/api/pages', pagesRouter);
}; };

View File

@ -36,32 +36,11 @@ module.exports = function(app) {
res.status(200).send(response); res.status(200).send(response);
}) })
.catch(function(e) { .catch(function(e) {
'use strict';
console.error(e); console.error(e);
res.status(401).end(); res.status(401).end();
}); });
};
});
profilesRouter.post('/', function(req, res) {
res.status(201).end();
});
profilesRouter.get('/:id', function(req, res) {
res.send({
profiles: {
id: req.params.id
} }
}); });
});
profilesRouter.put('/:id', function(req, res) {
res.send({
profiles: {
id: req.params.id
}
});
});
profilesRouter.patch('/:id', function(req, res) { profilesRouter.patch('/:id', function(req, res) {
var data = req.body.data; var data = req.body.data;
@ -85,7 +64,6 @@ module.exports = function(app) {
res.status(200).send(response); res.status(200).send(response);
}) })
.catch(function(err) { .catch(function(err) {
'use strict';
console.error(err); console.error(err);
res.status(401).end(); res.status(401).end();
}); });
@ -96,16 +74,6 @@ module.exports = function(app) {
res.status(204).end(); res.status(204).end();
}); });
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// Npm install --save-dev body-parser
// After installing, you need to `use` the body-parser for
// this mock uncommenting the following line:
//
//App.use('/api/profiles', require('body-parser').json());
app.use('/api/profiles', require('body-parser').json()); app.use('/api/profiles', require('body-parser').json());
app.use('/api/profiles', app.use('/api/profiles',
require('body-parser').json({type: 'application/vnd.api+json'})); require('body-parser').json({type: 'application/vnd.api+json'}));

View File

@ -16,7 +16,6 @@ module.exports = function(app) {
}); });
tokenRouter.post('/', function(req, res) { tokenRouter.post('/', function(req, res) {
logger.debug('POST');
if (req.body.hasOwnProperty('grant_type')) { if (req.body.hasOwnProperty('grant_type')) {
if (req.body.grant_type === 'password') { if (req.body.grant_type === 'password') {
dbAccounts.findAccount({ dbAccounts.findAccount({
@ -53,37 +52,6 @@ module.exports = function(app) {
}); });
tokenRouter.get('/:id', function(req, res) {
res.send({
token: {
id: req.params.id
}
});
});
tokenRouter.put('/:id', function(req, res) {
res.send({
token: {
id: req.params.id
}
});
});
tokenRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// Npm install --save-dev body-parser
// After installing, you need to `use` the body-parser for
// this mock uncommenting the following line:
//
//app.use('/token', require('body-parser').json());
// app.use('/token', require('body-parser').text());
app.use('/token', require('body-parser').urlencoded()); app.use('/token', require('body-parser').urlencoded());
app.use('/token', tokenRouter); app.use('/token', tokenRouter);

View File

@ -7,3 +7,9 @@
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
#image.img {
max-width: 300px;
max-height: 300px;
}

View File

@ -48,8 +48,6 @@ module.exports = function(db) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
db.one('select * from getAccountDetails($1);',[uid]) db.one('select * from getAccountDetails($1);',[uid])
.then(function(d) { .then(function(d) {
console.log('+ sqlGetAccountDetails');
console.log(d);
return resolve(d); return resolve(d);
}) })
.catch((err)=> { .catch((err)=> {
@ -186,7 +184,7 @@ module.exports = function(db) {
}); });
}; };
//makeMemberOf(cid, uid) //MakeMemberOf(cid, uid)
module.makeMemberOf = function(cid, uid) { module.makeMemberOf = function(cid, uid) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sqlMakeMemberOf(cid, uid) this.sqlMakeMemberOf(cid, uid)

View File

@ -17,20 +17,14 @@ module.exports = function(db) {
var module = {}; var module = {};
module.getLatestAddedPage = function() { module.getLatestAddedPage = function() {
console.log('+ getLatestAddedPage');
//select '/export/' || pages.pid::text || '.html' as fullpath from pages order by id desc limit 1;
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
db.oneOrNone( db.oneOrNone(
"select 'export/' || pages.pid::text || '.html' as fullpath from pages order by id desc limit 1;") "select 'export/' || pages.pid::text || '.html' as fullpath from pages order by id desc limit 1;")
.then((d) => { .then((d) => {
console.log(d);
console.log('- getlastaddedpage');
return resolve(d); return resolve(d);
}) })
.catch((err)=> { .catch((err)=> {
console.log('+getLatestAddedPage failed');
console.log(err);
return reject(err); return reject(err);
}); });
}); });
@ -46,8 +40,6 @@ module.exports = function(db) {
return resolve(d); return resolve(d);
}) })
.catch((err)=> { .catch((err)=> {
console.log('+getPageList failed');
console.log(err);
return reject(err); return reject(err);
}); });
}); });
@ -69,17 +61,12 @@ module.exports = function(db) {
"type": "page", "type": "page",
"attributes": attributeObj "attributes": attributeObj
}; };
// { data: [ { "id": "56b7ecbc1ef21172377d6159", "type": "guest", "attributes": { "name":"Ray","message":"First ever guest post entry" } }, ... ] }
rArray.push(newObj); rArray.push(newObj);
} }
return resolve(rArray); return resolve(rArray);
}) })
.catch((err)=> { .catch((err)=> {
console.log('+getPageList failed');
console.log(err);
return reject(err); return reject(err);
}); });
}); });
@ -88,14 +75,10 @@ module.exports = function(db) {
module.sqlInsertPage = function(data) { module.sqlInsertPage = function(data) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
db.func('upsert_page', data) db.func('upsert_page', data)
.then((d)=> { .then(()=> {
console.log(d);
console.log('+sqlInsertPage OK');
return resolve('ok'); return resolve('ok');
}) })
.catch((err)=> { .catch((err)=> {
console.log('+sqlInsertPage failed');
console.log(err);
return reject(err); return reject(err);
}); });
}); });
@ -106,7 +89,6 @@ module.exports = function(db) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let _data, _jsonData; let _data, _jsonData;
console.log(data);
_data = $U.cloneTrim(data.attributes); _data = $U.cloneTrim(data.attributes);
if (typeof _data.pid === 'undefined' || _data.pid === null) { if (typeof _data.pid === 'undefined' || _data.pid === null) {
@ -136,16 +118,12 @@ module.exports = function(db) {
JSON.stringify(_jsonData) JSON.stringify(_jsonData)
]; ];
console.log(sqlData);
this.sqlInsertPage(sqlData) this.sqlInsertPage(sqlData)
.then(function(d) { .then(function() {
console.log('Inserted');
console.log(d);
data.attributes = _data; data.attributes = _data;
return resolve(data); return resolve(data);
}) })
.catch(function(err) { .catch(function(err) {
console.log('Failed to insert');
return reject(err); return reject(err);
}); });

View File

@ -26,8 +26,7 @@ var MDERRORS = new function() {
}; };
this.error = function(code) { this.error = function(code) {
var estring = ''; var estring = errors[code].name + ': ' + errors[code].title + '\nCode: ' + code + '\n';
estring = errors[code].name + ': ' + errors[code].title + '\nCode: ' + code + '\n';
logger.error(estring); logger.error(estring);