Download spectrum/api/mutations/user/banUser.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/mutations/user/banUser.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/mutations/user/banUser.js
-
curl -L -o banUser.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/mutations/user/banUser.js
1.19 kB
| // @flow | |
| import { isAuthedResolver, isAdmin } from '../../utils/permissions'; | |
| import UserError from '../../utils/UserError'; | |
| import type { GraphQLContext } from '../../'; | |
| import { banUser } from 'shared/db/queries/user'; | |
| type BanUserInput = { | |
| input: { | |
| userId: string, | |
| reason: string, | |
| }, | |
| }; | |
| export default isAuthedResolver( | |
| async (_: any, args: BanUserInput, ctx: GraphQLContext) => { | |
| const { | |
| input: { userId, reason }, | |
| } = args; | |
| const { loaders, user: currentUser } = ctx; | |
| if (!isAdmin(currentUser.id)) { | |
| return new UserError('You don’t have permission to do that.'); | |
| } | |
| if (currentUser.id === userId) { | |
| return new UserError('You cannot ban yourself.'); | |
| } | |
| const reportedUser = await loaders.user.load(userId); | |
| if (!reportedUser) { | |
| return new UserError(`User with ID ${userId} does not exist.`); | |
| } | |
| if (reportedUser.bannedAt) { | |
| return new UserError('This user has already been banned'); | |
| } | |
| return banUser({ | |
| userId, | |
| reason, | |
| currentUserId: currentUser.id, | |
| }) | |
| .then(() => { | |
| return true; | |
| }) | |
| .catch(err => new UserError(err.message)); | |
| } | |
| ); | |