This is a backend API server written with Nest.js. This application is suggested to be used with the frontend web application here
Before starting the app, remember to add a .env
file and you can reference the .env.example
in the repo
yarn && yarn start
yarn build && yarn start:prod
yarn test
add --coverage
flag if you wanna check coverage
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---|---|---|---|---|---|
All files | 99.15 | 100 | 100 | 99.04 | |
pokeGuess | 100 | 100 | 100 | 100 | |
pokeGuess.controller.ts | 100 | 100 | 100 | 100 | |
pokeGuess.repository.ts | 100 | 100 | 100 | 100 | |
pokeGuess.service.ts | 100 | 100 | 100 | 100 | |
pokeGuess/transformers | 100 | 100 | 100 | 100 | |
pokemonTransformer.ts | 100 | 100 | 100 | 100 | |
questionTransformer.ts | 100 | 100 | 100 | 100 | |
pokeGuess/utils | 92.85 | 100 | 100 | 90.9 | |
randomPokemonHelper.ts | 92.85 | 100 | 100 | 90.9 | 13 |
yarn compose
if your interested in the command checkout package.json
The basic design is demonstrated below.
Request -> Controller -> Service -> Repository
-
Request will first hit controller. Then any information will be passed to the Service directly
-
In Service, that's where I put the logics of how the information should be process. Data will be gathered from Repository and transformers will be injected here and transform to desire response.
-
Repository is solely designed to isolate API callings from the
pokeapi
. In normal use cases, this repository is used to query the DB and return raw data. No/Minimal logic should be left here.
This route is as simple as it is named. This route will return a trivia question with random pokemons.
Response
{
"pokemonId": 1,
"pokemonName": "bulbasaur",
"pokemonCry": "https://raw.githubusercontent.com/PokeAPI/cries/main/cries/pokemon/latest/1.ogg",
"pokemonImg": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
"pokemonNameList": [
"venusaur","bulbasaur","caterpie","pidgeotto"
]
}
This api require a request body of answer information which includes pokemon name of player's answer
and pokemon id of the correct answer
. Then it will validate the answer and response with the correct answer information and whether the player is correct
Body
{
"pokemonId": 1,
"answer": "bulbasaur"
}
Response
{
"correct": true,
"image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
"pokemonName": "bulbasaur"
}
A Swagger doc is generated when you start this application and it will be available at {Base_URL}/api