File size: 820 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
26
27
28
29
30
31
32
33
// @flow
import type { GraphQLContext } from '../..';
import UserError from '../../utils/UserError';
import {
  toggleCommunityNoindex,
  getCommunityById,
} from '../../models/community';
import {
  isAuthedResolver as requireAuth,
  canAdministerCommunity,
} from '../../utils/permissions';

type Input = {
  communityId: string,
};

export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
  const { communityId } = args;
  const { user, loaders } = ctx;

  if (!(await canAdministerCommunity(user.id, communityId, loaders))) {
    return new UserError("You don't have permission to do this.");
  }

  const community = await getCommunityById(communityId);

  if (!community) {
    return new UserError('This community does not exist.');
  }

  return toggleCommunityNoindex(communityId);
});