Search improvements

This commit is contained in:
Jori Lallo
2017-12-03 16:50:50 -08:00
parent cd2cbf1c15
commit 5df2983ef6
6 changed files with 86 additions and 12 deletions

View File

@@ -142,13 +142,17 @@ router.post('documents.revisions', auth(), pagination(), async ctx => {
};
});
router.post('documents.search', auth(), async ctx => {
router.post('documents.search', auth(), pagination(), async ctx => {
const { query } = ctx.body;
const { offset, limit } = ctx.state.pagination;
ctx.assertPresent(query, 'query is required');
const user = await ctx.state.user;
const documents = await Document.searchForUser(user, query);
const documents = await Document.searchForUser(user, query, {
offset,
limit,
});
const data = await Promise.all(
documents.map(async document => await presentDocument(ctx, document))