Files
Compass/backend/api/src/ban-user.ts

18 lines
653 B
TypeScript

import {APIErrors, APIHandler} from 'api/helpers/endpoint'
import {isAdminId} from 'common/envs/constants'
import {trackPublicEvent} from 'shared/analytics'
import {throwErrorIfNotMod} from 'shared/helpers/auth'
import {updateUser} from 'shared/supabase/users'
import {log} from 'shared/utils'
export const banUser: APIHandler<'ban-user'> = async (body, auth) => {
const {userId, unban} = body
await throwErrorIfNotMod(auth.uid)
if (isAdminId(userId)) throw APIErrors.forbidden('Cannot ban admin')
await trackPublicEvent(auth.uid, 'ban user', {
userId,
})
await updateUser(userId, {isBannedFromPosting: !unban})
log('updated user')
}