File size: 579 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// @flow
import type { GraphQLContext } from '../../';
import type { DBCommunity } from 'shared/types';
import { getThreads } from '../../models/thread';
import { canViewCommunity } from '../../utils/permissions';
export default async (root: DBCommunity, _: any, ctx: GraphQLContext) => {
const { watercoolerId, id } = root;
const { user, loaders } = ctx;
if (!watercoolerId) return null;
if (!await canViewCommunity(user, id, loaders)) {
return null;
}
return await getThreads([watercoolerId]).then(
res => (res && res.length > 0 ? res[0] : null)
);
};
|