Tidy, move recent documents to query scope
This commit is contained in:
@ -24,7 +24,7 @@ router.post('collections.create', auth(), async ctx => {
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
data: await presentCollection(ctx, atlas, true),
|
||||
data: await presentCollection(ctx, atlas),
|
||||
};
|
||||
});
|
||||
|
||||
@ -33,7 +33,7 @@ router.post('collections.info', auth(), async ctx => {
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
const atlas = await Collection.findOne({
|
||||
const atlas = await Collection.scope('withRecentDocuments').findOne({
|
||||
where: {
|
||||
id,
|
||||
teamId: user.teamId,
|
||||
@ -43,13 +43,13 @@ router.post('collections.info', auth(), async ctx => {
|
||||
if (!atlas) throw httpErrors.NotFound();
|
||||
|
||||
ctx.body = {
|
||||
data: await presentCollection(ctx, atlas, true),
|
||||
data: await presentCollection(ctx, atlas),
|
||||
};
|
||||
});
|
||||
|
||||
router.post('collections.list', auth(), pagination(), async ctx => {
|
||||
const user = ctx.state.user;
|
||||
const collections = await Collection.findAll({
|
||||
const collections = await Collection.scope('withRecentDocuments').findAll({
|
||||
where: {
|
||||
teamId: user.teamId,
|
||||
},
|
||||
@ -58,16 +58,10 @@ router.post('collections.list', auth(), pagination(), async ctx => {
|
||||
limit: ctx.state.pagination.limit,
|
||||
});
|
||||
|
||||
// Collectiones
|
||||
let data = [];
|
||||
await Promise.all(
|
||||
collections.map(async atlas => {
|
||||
return data.push(await presentCollection(ctx, atlas, true));
|
||||
})
|
||||
const data = await Promise.all(
|
||||
collections.map(async atlas => await presentCollection(ctx, atlas))
|
||||
);
|
||||
|
||||
data = _.orderBy(data, ['updatedAt'], ['desc']);
|
||||
|
||||
ctx.body = {
|
||||
pagination: ctx.state.pagination,
|
||||
data,
|
||||
|
@ -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