-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from fac-14/backend-ref
Backend ref
- Loading branch information
Showing
8 changed files
with
1,607 additions
and
1,545 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
exports.get = (req, res) => { | ||
res.render('results', { | ||
layout: 'scrollable' | ||
}); | ||
res.render('results', | ||
{ | ||
layout: 'scrollable', | ||
progressamt: '100', | ||
title: 'Results', | ||
pageInfo: 'Based on the checkboxes you have selected, here are your results.' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const queries = require('../model/index') | ||
const queryString = require('query-string'); | ||
|
||
exports.get = (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); | ||
|
||
queries.getData(backgroundArr, resourceArr) | ||
.then( dbObj => { | ||
const resultArray = arrangeArray(dbObj.rows); | ||
console.log('resultArray', resultArray); | ||
const outArray = filterByType(resultArray); | ||
console.log('OUTPUT ARRAY', outArray); | ||
//res.render('results', {outArray}); | ||
response.send(outArray); | ||
}) | ||
.catch(err => console.log(err)); | ||
|
||
function filterByType(inArray) { | ||
const types = ['meetup', 'online course', 'article', 'classroom course']; | ||
const outArr = [] | ||
types.forEach(mytype => { | ||
//outArr[meetup]= filtered result | ||
// setting keys to values from filter function | ||
outArr[mytype] = inArray.filter(function (value) { | ||
return value.resource_type == mytype; | ||
}) | ||
}) | ||
return outArr; | ||
} | ||
//to arrange repeated resource as {resource_id='1', resource_name='codebar', direct=['age','ethnicity'], indirect=['disability']},.... | ||
function arrangeArray(inArray) { | ||
var resultArray = []; //empty array to start with | ||
for (let i = 0; i < inArray.length; i++) { | ||
if (i == 0) { | ||
//populate new resouce in our result array | ||
resultArrIndx = 0; | ||
resultArray.push({ | ||
resource_id: inArray[i].resource_id, resource_name: inArray[i].resource_name, | ||
url: inArray[i].url, resource_type: inArray[i].resource_type | ||
}); | ||
resultArray[resultArrIndx].direct = []; | ||
resultArray[resultArrIndx].indirect = []; | ||
//if incoming demo_tag_relevance is direct push it into resultArray[resultArrIndx].direct array else | ||
//push into resultArray[resultArrIndx].indirect array | ||
if (inArray[i].relevance === 'direct') { | ||
resultArray[resultArrIndx].direct.push(inArray[i].tag_name); | ||
} else { | ||
resultArray[resultArrIndx].indirect.push(inArray[i].tag_name); | ||
} | ||
resultArrIndx++; | ||
} | ||
else if (resultArray[resultArrIndx - 1].resource_id == inArray[i].resource_id) { | ||
if (inArray[i].demo_tag_relevance === 'direct') { | ||
resultArray[resultArrIndx - 1].direct.push(inArray[i].tag_name); | ||
} else { | ||
resultArray[resultArrIndx - 1].indirect.push(inArray[i].tag_name); | ||
} | ||
} | ||
else { | ||
//populate new resouce in our result array | ||
//create new key demo_tag_relevance and push {tagname:'tagname value', relevance:'rel value'} | ||
resultArray.push({ | ||
resource_id: inArray[i].resource_id, resource_name: inArray[i].resource_name, | ||
url: inArray[i].url, resource_type: inArray[i].resource_type | ||
}); | ||
resultArray[resultArrIndx].direct = []; | ||
resultArray[resultArrIndx].indirect = []; | ||
//if incoming demo_tag_relevance is direct push it into resultArray[resultArrIndx].direct array else | ||
//push into resultArray[resultArrIndx].indirect array | ||
if (inArray[i].relevance === 'direct') { | ||
resultArray[resultArrIndx].direct.push(inArray[i].tag_name); | ||
} else { | ||
resultArray[resultArrIndx].indirect.push(inArray[i].tag_name); | ||
} | ||
resultArrIndx++; | ||
} | ||
} //end of for loop | ||
|
||
return resultArray; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const getDemoTagId = require("./get_demo_tag_id"); | ||
const getResourceDetail = require("./get_resource_detail"); | ||
const getResource = require("./getResource"); | ||
const getData = require("./getData"); | ||
|
||
module.exports = { | ||
getDemoTagId: getDemoTagId, | ||
getResourceDetail: getResourceDetail, | ||
getResource: getResource | ||
getData: getData | ||
}; |