Tidy, move recent documents to query scope
This commit is contained in:
@ -21,7 +21,9 @@ router.post('documents.list', auth(), pagination(), async ctx => {
|
||||
include: [{ model: Star, as: 'starred', where: { userId: user.id } }],
|
||||
});
|
||||
|
||||
let data = await Promise.all(documents.map(doc => presentDocument(ctx, doc)));
|
||||
const data = await Promise.all(
|
||||
documents.map(document => presentDocument(ctx, document))
|
||||
);
|
||||
|
||||
ctx.body = {
|
||||
pagination: ctx.state.pagination,
|
||||
@ -42,7 +44,7 @@ router.post('documents.viewed', auth(), pagination(), async ctx => {
|
||||
limit: ctx.state.pagination.limit,
|
||||
});
|
||||
|
||||
let data = await Promise.all(
|
||||
const data = await Promise.all(
|
||||
views.map(view => presentDocument(ctx, view.document))
|
||||
);
|
||||
|
||||
@ -70,7 +72,7 @@ router.post('documents.starred', auth(), pagination(), async ctx => {
|
||||
limit: ctx.state.pagination.limit,
|
||||
});
|
||||
|
||||
let data = await Promise.all(
|
||||
const data = await Promise.all(
|
||||
views.map(view => presentDocument(ctx, view.document))
|
||||
);
|
||||
|
||||
@ -99,8 +101,7 @@ router.post('documents.info', auth(), async ctx => {
|
||||
|
||||
ctx.body = {
|
||||
data: await presentDocument(ctx, document, {
|
||||
includeCollection: document.private,
|
||||
includeCollaborators: true,
|
||||
includeViews: true,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@ -113,15 +114,8 @@ router.post('documents.search', auth(), async ctx => {
|
||||
|
||||
const documents = await Document.searchForUser(user, query);
|
||||
|
||||
const data = [];
|
||||
await Promise.all(
|
||||
documents.map(async document => {
|
||||
data.push(
|
||||
await presentDocument(ctx, document, {
|
||||
includeCollaborators: true,
|
||||
})
|
||||
);
|
||||
})
|
||||
const data = await Promise.all(
|
||||
documents.map(async document => await presentDocument(ctx, document))
|
||||
);
|
||||
|
||||
ctx.body = {
|
||||
@ -204,9 +198,7 @@ router.post('documents.create', auth(), async ctx => {
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: await presentDocument(ctx, newDocument, {
|
||||
includeCollaborators: true,
|
||||
}),
|
||||
data: await presentDocument(ctx, newDocument),
|
||||
};
|
||||
});
|
||||
|
||||
@ -232,9 +224,7 @@ router.post('documents.update', auth(), async ctx => {
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: await presentDocument(ctx, document, {
|
||||
includeCollaborators: true,
|
||||
}),
|
||||
data: await presentDocument(ctx, document),
|
||||
};
|
||||
});
|
||||
|
||||
@ -273,10 +263,7 @@ router.post('documents.move', auth(), async ctx => {
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: await presentDocument(ctx, document, {
|
||||
includeCollaborators: true,
|
||||
collection: collection,
|
||||
}),
|
||||
data: await presentDocument(ctx, document),
|
||||
};
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user