import { Controller } from '@/application/controllers' ; import { HttpResponse , ok } from '@/application/helpers' ; import { ValidationBuilder as Builder , Validator } from '@/application/validation' ; import { ChangeProfilePicture } from '@/domain/use-cases' ; type HttpRequest = { file ? : { buffer : Buffer ; mimeType : string ; } ; userId : string ; } ; type Model = { initials ? : string ; pictureUrl ? : string ; } ; export class SavePictureController extends Controller { constructor ( private readonly changeProfilePicture ) { super ( ) ; } override async perform ( { file , userId } ) { const { initials , pictureUrl } = await this . changeProfilePicture ( { id : userId , file } ) ; return ok ( { initials , pictureUrl } ) ; } override buildValidators ( { file } ) { if ( file === undefined ) return [ ] ; return [ ... Builder . of ( { value : file , fieldName : 'file' } ) . required ( ) . image ( { allowed : [ 'png' , 'jpg' ] , maxSizeInMb : 5 } ) . build ( ) ] ; } }