This commit is contained in:
Tom Moor
2017-07-15 16:08:12 -07:00
parent 0caff8c393
commit 66e4995885
8 changed files with 15 additions and 12 deletions

View File

@ -13,12 +13,13 @@ router.post('documents.list', auth(), pagination(), async ctx => {
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
const documents = await Document.findAll({
const userId = user.id;
const starredScope = { method: ['withStarred', userId] };
const documents = await Document.scope('defaultScope', starredScope).findAll({
where: { teamId: user.teamId },
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
include: [{ model: Star, as: 'starred', where: { userId: user.id } }],
});
const data = await Promise.all(