Skip to content

Commit

Permalink
Work in progress. Parse query string. Relates > #25
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualDOMinic committed Sep 18, 2018
1 parent 29dd074 commit 6f09c73
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 59 deletions.
17 changes: 15 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"node-sass-middleware": "^0.11.0",
"pg": "^7.4.3",
"pg-promise": "^8.4.6",
"query-string": "^6.1.0",
"querystring": "^0.2.0",
"sequelize": "^4.38.0",
"serve-favicon": "^2.5.0"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ router.get('/welcome', welcome.get);
router.get('/background', background.get);
router.get('/resources', resources.get);
router.get('/more-info', moreinfo.get);
router.get('/results', results.get);
router.get('/results', results.post); //used to be results.get

// trigger 500 error for testing

Expand Down
16 changes: 15 additions & 1 deletion src/controllers/results.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
const queries = require('../model/index')
const queryString = require('query-string');

exports.post = (req, response) => {
var queryObj = queryString.parseUrl(req.url).query;
var backgroundArr = queryObj.bg.split(",");
var resourceArr = queryObj.rsc.split(",");
console.log("bg Arr is", backgroundArr, "rsc Arr is", resourceArr);
const demo_tags = [];
}

// Old code:
/*
exports.get = (req, res) => {
res.render('results', {
layout: 'scrollable'
});
}
}
*/
53 changes: 0 additions & 53 deletions src/model/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,3 @@ const getResource = inputArray => {
};
module.exports = getResource;

console.log("HERE");

// getResource(['age', 'disability', 'gender'])
// .then(res => console.log(res.rows))
// .catch(err => console.log(err))
const resultArr = getResource(["age", "disability", "gender"])
.then(res => {
var resultArr = res.rows;
var newAns = resultArr.reduce(reducer);
console.log("HELLO", newAns);
})
.catch(err => console.log(err));

////////

//myArray.reduce(reducer)
// var myarr = [1, 2, 3];
// const reducer = (accumulator, currentvalue) => {
// return accumulator + currentvalue;
// };

// var sum = myarr.reduce(reducer);
// console.log(sum);
var accumulator = []; //empty array to start with
const reducer = (accumulator, currentvalue) => {
// accumulator.forEach(function(element) {
// if (element.resource_id == currentvalue.resource_id) {
// //if one of the relevance is direct set our result's relevance to direct
// if (element.relevance == "direct" || currentvalue.relevance == "direct") {
// element.relevane = "direct";
// }
// } else {
// //populate new resouce in our result array
// accumulator.push(currentvalue);
// }
// });
for (let i = 0; i < accumulator.length; i++) {
if (accumulator[i].resource_id == currentvalue.resource_id) {
if (
accumulator[i].relevance == "direct" ||
currentvalue.relevance == "direct"
) {
accumulator[i].relevance = "direct";
}
} else {
//populate new resouce in our result array
accumulator.push(currentvalue);
}
}
};

//var newAns = resultArr.reduce(reducer);
//console.log("HELLO", newAns);
2 changes: 1 addition & 1 deletion src/model/get_resource_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const db = require("../database/db_connection");

const getResourceDetail = resourceId => {
return new Promise((resolve, reject) => {
db.query(`SELECT * from resource WHERE id ='${resourceId}' `)
db.query(`SELECT * from resource WHERE resource_id ='${resourceId}' `)
.then(res => resolve(res))
.catch(err => reject(err));
});
Expand Down
2 changes: 1 addition & 1 deletion src/model/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const getDemoTagId = require("./get_demo_tag_id");
const getResourceDetail = require("./get_resource_detail");
const getResource = require("./getResource");
const getResource = require("./getData");

module.exports = {
getDemoTagId: getDemoTagId,
Expand Down

0 comments on commit 6f09c73

Please sign in to comment.