Added more views and atlas APIs

This commit is contained in:
Jori Lallo
2016-05-07 11:52:08 -07:00
parent 84ba65f72a
commit cbe9c0b6ee
22 changed files with 397 additions and 27 deletions

52
server/api/atlases.js Normal file
View File

@ -0,0 +1,52 @@
import Router from 'koa-router';
import httpErrors from 'http-errors';
import auth from './authentication';
import pagination from './middlewares/pagination';
import { presentAtlas } from '../presenters';
import { Team, Atlas } from '../models';
const router = new Router();
router.post('atlases.info', auth(), async (ctx) => {
let { id } = ctx.request.body;
ctx.assertPresent(id, 'id is required');
const team = await ctx.state.user.getTeam();
const atlas = await Atlas.findOne({
where: {
id: id,
teamId: team.id,
},
});
if (!atlas) throw httpErrors.NotFound();
ctx.body = {
data: presentAtlas(atlas),
};
});
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,
},
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
ctx.body = {
pagination: ctx.state.pagination,
data: atlases.map((atlas) => {
return presentAtlas(atlas);
})
};
});
export default router;

View File

@ -6,6 +6,7 @@ import Sequelize from 'sequelize';
import auth from './auth';
import user from './user';
import atlases from './atlases';
import validation from './validation';
@ -42,6 +43,7 @@ api.use(validation());
router.use('/', auth.routes());
router.use('/', user.routes());
router.use('/', atlases.routes());
// Router is embedded in a Koa application wrapper, because koa-router does not
// allow middleware to catch any routes which were not explicitly defined.