Team details settings page

This commit is contained in:
Tom Moor
2018-05-31 12:44:32 -07:00
parent fb7a8f0312
commit 10a0ffe472
12 changed files with 226 additions and 18 deletions

View File

@ -1,13 +1,33 @@
// @flow
import Router from 'koa-router';
import { User } from '../models';
import { User, Team } from '../models';
import { publicS3Endpoint } from '../utils/s3';
import auth from '../middlewares/authentication';
import pagination from './middlewares/pagination';
import { presentUser } from '../presenters';
import { presentUser, presentTeam } from '../presenters';
import policy from '../policies';
const { authorize } = policy;
const router = new Router();
router.post('team.update', auth(), async ctx => {
const { name, avatarUrl } = ctx.body;
const endpoint = publicS3Endpoint();
const user = ctx.state.user;
const team = await Team.findById(user.teamId);
authorize(user, 'update', team);
if (name) team.name = name;
if (avatarUrl && avatarUrl.startsWith(`${endpoint}/uploads/${user.id}`)) {
team.avatarUrl = avatarUrl;
}
await team.save();
ctx.body = { data: await presentTeam(ctx, team) };
});
router.post('team.users', auth(), pagination(), async ctx => {
const user = ctx.state.user;