Team details settings page
This commit is contained in:
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user