Working recently edited list

This commit is contained in:
Tom Moor
2017-11-19 21:32:18 -08:00
parent dc242038ff
commit 81edb55d56
7 changed files with 49 additions and 9 deletions

View File

@ -15,14 +15,17 @@ const authDocumentForUser = (ctx, document) => {
const router = new Router();
router.post('documents.list', auth(), pagination(), async ctx => {
let { sort = 'updatedAt', direction } = ctx.body;
let { sort = 'updatedAt', direction, collectionId } = ctx.body;
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
let where = { teamId: user.teamId };
if (collectionId) where = { ...where, atlasId: collectionId };
const userId = user.id;
const starredScope = { method: ['withStarred', userId] };
const documents = await Document.scope('defaultScope', starredScope).findAll({
where: { teamId: user.teamId },
where,
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,