Skip to content

Commit

Permalink
Merge pull request #6 from tobias-g1/develop
Browse files Browse the repository at this point in the history
Add reputation for search results, resolve issue with pipeline returning incorrect search results
  • Loading branch information
surpassinggoogle committed Mar 10, 2019
2 parents a99368f + be0acdf commit d1ea395
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/controllers/search.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Post = require('../model/post')
const {handleErr} = require('../utils')
const {calcRep} = require('../utils')
const steem = require('steem')

exports.search = (req, res) => {
Expand Down Expand Up @@ -42,14 +42,16 @@ exports.search = (req, res) => {
)
}

let matchOptions = {$match: {
price: { $lte: maxPrice, $gte: minPrice }
}}
let matchOptions = {$match: {}}

if (type) {
matchOptions.$match['type'] = type
}

if (minPrice && maxPrice) {
matchOptions.$match['price'] = { $lte: maxPrice, $gte: minPrice }
}

if (currency && currency.toLowerCase() !== 'any') {
matchOptions.$match['currency'] = currency
}
Expand Down Expand Up @@ -78,6 +80,8 @@ exports.search = (req, res) => {
}}
)

console.log(JSON.stringify(pipeline))

try {
Post.aggregate(pipeline).exec((err, result) => {
if (!err) {
Expand All @@ -90,6 +94,7 @@ exports.search = (req, res) => {
steem.api.getContent(singleResult.author, singleResult.permlink, function (err, post) {
if (!err) {
post.json_metadata = JSON.parse(post.json_metadata)
post.rep = calcRep(post.author_reputation)
const mergedResults = {...dbData, ...post}
combinedResults.push(mergedResults)
if (combinedResults.length === searchData.length) {
Expand Down

0 comments on commit d1ea395

Please sign in to comment.