import { NextFunction , Request , Response , Router } from "express" ; import { PokemonService } from "../services/pokemon.service" ; export class PokemonController { public router = Router ( ) ; constructor ( private pokemonService ) { this . setRoutes ( ) ; } public setRoutes ( ) { this . router . route ( "/" ) . get ( this . hello ) ; this . router . route ( "/all" ) . get ( this . findAll ) ; this . router . route ( "/" ) . post ( this . add ) ; this . router . route ( "/:id" ) . delete ( this . delete ) . put ( this . update ) ; } private hello = ( _ , res ) => { const welcomeMessage = this . pokemonService . welcomeMessage ( ) ; res . send ( welcomeMessage ) ; } ; private findAll = async ( _ , res , next ) => { const pokemon = await this . pokemonService . find ( ) ; res . send ( pokemon ) ; } ; private add = async ( req , res , next ) => { const addPokemonResult = await this . pokemonService . add ( req . body ) ; res . send ( addPokemonResult ) ; } ; private delete = async ( req , res , next ) => { const deletePokemonResult = await this . pokemonService . delete ( req . params . id ) ; res . send ( deletePokemonResult ) ; } ; private update = async ( req , res , next ) => { const updatePokemonResult = await this . pokemonService . update ( req . params . id , req . body ) ; res . send ( updatePokemonResult ) ; } ; }