mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-10 09:39:36 -04:00
18 lines
653 B
TypeScript
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')
|
|
}
|