import { HttpError } from "../errors/http.error" ; import { IPokemon } from "../interfaces/pokemon.interface" ; import Pokemon from "../models/pokemon.model" ; import { WELCOME_MESSAGE } from "../constants/pokeapi.constants" ; export class PokemonService { public welcomeMessage ( ) { return WELCOME_MESSAGE ; } public find ( ) { return Pokemon . find ( { } ) . exec ( ) ; } public add ( pokemon ) { const newPokemon = new Pokemon ( pokemon ) ; return newPokemon . save ( ) ; } public async delete ( id ) { const deletedPokemon = await Pokemon . findByIdAndDelete ( id ) . exec ( ) ; if ( ! deletedPokemon ) { throw new HttpError ( `Pokemon with id '${ id }' not found` , 404 ) ; } return deletedPokemon ; } public async update ( id , pokemon ) { const updatedPokemon = await Pokemon . findByIdAndUpdate ( id , pokemon ) . exec ( ) ; if ( ! updatedPokemon ) { throw new HttpError ( `Pokemon with id '${ id }' not found` , 404 ) ; } return updatedPokemon ; } }