jefer94/choco

View on GitHub
services/authenticator/src/actions/deleteScope.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Scope } from '../models'

type DeleteScope = {
  readonly data?: {
    readonly name: string
  }
  readonly error?: string
}

/**
 * Delete scope.
 * @param name - Scope name.
 * @returns Was deleted?.
 */
export default async function deleteScope(name: string): Promise<DeleteScope> {
  const scope = await Scope.findOneAndRemove({ name }).populate('users', '-password').exec()
  if (scope) return { data: scope }
  return { error: 'scope not exist' }
}