Download spectrum/api/queries/user/communityConnection.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/user/communityConnection.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/queries/user/communityConnection.js
-
curl -L -o communityConnection.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/user/communityConnection.js
1.29 kB
| // @flow | |
| import type { DBUser } from 'shared/types'; | |
| import { | |
| getVisibleCommunitiesByUser, | |
| getPublicCommunitiesByUser, | |
| getCommunitiesByUser, | |
| } from '../../models/community'; | |
| import type { GraphQLContext } from '../../'; | |
| export default async (user: DBUser, _: any, ctx: GraphQLContext) => { | |
| const evaluatingUserId = user.id; | |
| const { loaders, user: currentUser } = ctx; | |
| let communities; | |
| if (!currentUser || !currentUser.id) { | |
| communities = await getPublicCommunitiesByUser(evaluatingUserId); | |
| } else if (evaluatingUserId === currentUser.id) { | |
| communities = await getCommunitiesByUser(currentUser.id); | |
| } else { | |
| communities = await getVisibleCommunitiesByUser( | |
| evaluatingUserId, | |
| currentUser.id | |
| ); | |
| } | |
| return { | |
| pageInfo: { | |
| hasNextPage: false, | |
| }, | |
| edges: communities.map(async community => { | |
| const permissions = await loaders.userPermissionsInCommunity.load([ | |
| user.id, | |
| community.id, | |
| ]); | |
| return { | |
| node: { | |
| ...community, | |
| contextPermissions: { | |
| communityId: community.id, | |
| isModerator: permissions ? permissions.isModerator : false, | |
| isOwner: permissions ? permissions.isOwner : false, | |
| }, | |
| }, | |
| }; | |
| }), | |
| }; | |
| }; | |