This commit is contained in:
Jori Lallo
2016-07-25 23:01:14 -07:00
parent f08087ebd1
commit c88cc1f83b

View File

@ -5,12 +5,12 @@ import _orderBy from 'lodash.orderby';
import auth from './authentication'; import auth from './authentication';
import pagination from './middlewares/pagination'; import pagination from './middlewares/pagination';
import { presentAtlas } from '../presenters'; import { presentAtlas } from '../presenters';
import { Team, Atlas } from '../models'; import { Atlas } from '../models';
const router = new Router(); const router = new Router();
router.post('atlases.create', auth(), async (ctx) => { router.post('atlases.create', auth(), async (ctx) => {
let { const {
name, name,
description, description,
type, type,
@ -32,13 +32,13 @@ router.post('atlases.create', auth(), async (ctx) => {
}); });
router.post('atlases.info', auth(), async (ctx) => { router.post('atlases.info', auth(), async (ctx) => {
let { id } = ctx.body; const { id } = ctx.body;
ctx.assertPresent(id, 'id is required'); ctx.assertPresent(id, 'id is required');
const user = ctx.state.user; const user = ctx.state.user;
const atlas = await Atlas.findOne({ const atlas = await Atlas.findOne({
where: { where: {
id: id, id,
teamId: user.teamId, teamId: user.teamId,
}, },
}); });
@ -66,7 +66,7 @@ router.post('atlases.list', auth(), pagination(), async (ctx) => {
// Atlases // Atlases
let data = []; let data = [];
await Promise.all(atlases.map(async (atlas) => { await Promise.all(atlases.forEach(async (atlas) => {
data.push(await presentAtlas(atlas, true)); data.push(await presentAtlas(atlas, true));
})); }));
@ -74,29 +74,29 @@ router.post('atlases.list', auth(), pagination(), async (ctx) => {
ctx.body = { ctx.body = {
pagination: ctx.state.pagination, pagination: ctx.state.pagination,
data: data, data,
}; };
}); });
router.post('atlases.updateNavigationTree', auth(), async (ctx) => { router.post('atlases.updateNavigationTree', auth(), async (ctx) => {
let { id, tree } = ctx.body; const { id, tree } = ctx.body;
ctx.assertPresent(id, 'id is required'); ctx.assertPresent(id, 'id is required');
const user = ctx.state.user; const user = ctx.state.user;
const atlas = await Atlas.findOne({ const atlas = await Atlas.findOne({
where: { where: {
id: id, id,
teamId: user.teamId, teamId: user.teamId,
}, },
}); });
if (!atlas) throw httpErrors.NotFound(); if (!atlas) throw httpErrors.NotFound();
const newTree = await atlas.updateNavigationTree(tree); await atlas.updateNavigationTree(tree);
ctx.body = { ctx.body = {
data: await presentAtlas(atlas, true), data: await presentAtlas(atlas, true),
}; };
}); });
export default router; export default router;