Fixes to data fetching

This commit is contained in:
Jori Lallo
2016-05-20 00:33:52 -07:00
parent d3a1eb2c21
commit 90310703ec
3 changed files with 16 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import Router from 'koa-router';
import httpErrors from 'http-errors';
import _orderBy from 'lodash/orderBy';
import auth from './authentication';
import pagination from './middlewares/pagination';
@@ -29,14 +30,14 @@ router.post('atlases.info', auth(), async (ctx) => {
router.post('atlases.list', auth(), pagination(), async (ctx) => {
let { teamId } = ctx.request.body;
ctx.assertPresent(teamId, 'teamId is required');
const team = await ctx.state.user.getTeam();
const atlases = await Atlas.findAll({
where: {
teamId: teamId,
teamId: team.id,
},
order: [
['updatedAt', 'DESC'],
],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
@@ -44,8 +45,10 @@ router.post('atlases.list', auth(), pagination(), async (ctx) => {
// Atlases
let data = [];
await Promise.all(atlases.map(async (atlas) => {
data.push(await presentAtlas(atlas));
}))
data.push(await presentAtlas(atlas, true));
}));
data = _orderBy(data, ['updatedAt'], ['desc']);
ctx.body = {
pagination: ctx.state.pagination,

View File

@@ -64,8 +64,8 @@ router.post('auth.slack', async (ctx) => {
user.setTeam(team);
ctx.body = { data: {
user: presentUser(user),
team: presentTeam(team),
user: await presentUser(user),
team: await presentTeam(team),
accessToken: user.getJwtToken(),
}};
});

View File

@@ -1,4 +1,5 @@
var marked = require('marked');
import marked from 'marked';
import Document from './models/Document';
export function presentUser(user) {
@@ -37,6 +38,9 @@ export function presentAtlas(atlas, includeRecentDocuments=false) {
atlasId: atlas.id,
},
limit: 10,
order: [
['updatedAt', 'DESC'],
],
});
let recentDocuments = [];