Errors when we have a user that was not signed in. Fixed to unpack the username value first, then pass it to the function.

This commit is contained in:
2018-03-08 10:32:19 +01:00
parent 13401a318a
commit 127db8b2fe

View File

@@ -10,15 +10,16 @@ const searchHistory = new SearchHistory();
function searchRequestController(req, res) { function searchRequestController(req, res) {
const user = req.loggedInUser; const user = req.loggedInUser;
const { query, page, type } = req.query; const { query, page, type } = req.query;
const username = user == undefined ? undefined : user.username;
Promise.resolve() Promise.resolve()
.then(() => searchHistory.create(user, query)) .then(() => searchHistory.create(username, query))
.then(() => requestRepository.search(query, page, type)) .then(() => requestRepository.search(query, page, type))
.then((searchResult) => { .then((searchResult) => {
res.send(searchResult); res.send(searchResult);
}) })
.catch((error) => { .catch((error) => {
res.status(500).send({ success: false, error: error.message }); res.status(500).send({ success: false, error: error });
}); });
} }