File size: 781 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// @flow
import type { GraphQLContext } from '../../';
import type { EditCommunityInput } from '../../models/community';
import UserError from '../../utils/UserError';
import { editCommunity } from '../../models/community';
import {
  isAuthedResolver as requireAuth,
  canModerateCommunity,
} from '../../utils/permissions';

export default requireAuth(
  // prettier-ignore
  async (_: any, args: EditCommunityInput, ctx: GraphQLContext) => {
    const { user, loaders} = ctx
    const { communityId } = args.input

    // user must own the community to edit the community
    if (!await canModerateCommunity(user.id, communityId, loaders)) {
      return new UserError("You don't have permission to edit this community.");
    }

    return editCommunity(args, user.id);
  }
);