Skip to content

Commit

Permalink
Ensure we always show sticky notes regardless of query
Browse files Browse the repository at this point in the history
Part of #74
  • Loading branch information
nebulade committed Oct 14, 2017
1 parent 65decee commit 70e64a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/database/things.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function getCollection(userId) {
config.db.createCollection(userId + '_things');
g_collections[userId] = config.db.collection(userId + '_things');
g_collections[userId].createIndex({ content: 'text' }, { default_language: 'none' });
g_collections[userId].createIndex({ sticky: 1 });
}

return g_collections[userId];
Expand Down
20 changes: 13 additions & 7 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,36 @@ function profile(req, res, next) {
}

function getAll(req, res, next) {
var query = { $and: [] };
// TODO make sticky selectable by the api to optionally not show sticky ones on search
var query = { $or: [ { sticky: true } ]};

if (req.query && req.query.filter) {
query.$and.push({
query.$or.push({
$text: { $search: String(req.query.filter) }
});
} else {
query.$or.push({ content: { $exists: true }});
}

var archiveQuery;
if (req.query && req.query.archived) {
query.$and.push({
archiveQuery = {
archived: true
});
};
} else {
query.$and.push({ $or: [{
archiveQuery = { $or: [{
archived: false
}, {
archived: { $exists: false }
}]});
}]};
}

var endQuery = { $and: [ archiveQuery, query ]};

var skip = isNaN(parseInt(req.query.skip)) ? 0 : parseInt(req.query.skip);
var limit = isNaN(parseInt(req.query.limit)) ? 10 : parseInt(req.query.limit);

logic.getAll(req.userId, query, skip, limit, function (error, result) {
logic.getAll(req.userId, endQuery, skip, limit, function (error, result) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, { things: result }));
});
Expand Down

0 comments on commit 70e64a7

Please sign in to comment.