import { Controller } from '@/application/controllers' ; import { HttpResponse , unauthorized , ok } from '@/application/helpers' ; import { ValidationBuilder as Builder , Validator } from '@/application/validation' ; import { AuthenticationError } from '@/domain/entities' ; import { FacebookAuthentication } from '@/domain/use-cases' ; type HttpRequest = { token : string ; } ; type Model = Error | { accessToken : string ; } ; export class FacebookLoginController extends Controller { constructor ( private readonly facebookAuthentication ) { super ( ) ; } async perform ( { token } ) { try { const accessToken = await this . facebookAuthentication ( { token } ) ; return ok ( accessToken ) ; } catch ( error ) { if ( error instanceof AuthenticationError ) return unauthorized ( ) ; throw error ; } } override buildValidators ( { token } ) { return [ ... Builder . of ( { value : token , fieldName : 'token' } ) . required ( ) . build ( ) ] ; } }