This project is designed for storing pokemons from an external api service. Also on the frontend pokemons will be display to loggedin users.
Postman Api Collection exported. Check Pokemon.postman_collection.json
Api address: https://pokeapi.co/docs/v2
- Generation: https://pokeapi.co/api/v2/pokemon?limit=151
- Generation: https://pokeapi.co/api/v2/pokemon?offset=151&limit=100
- Generation: https://pokeapi.co/api/v2/pokemon?offset=251&limit=135
- https://pokeapi.co/api/v2/generation/1
- https://pokeapi.co/api/v2/generation/2
- https://pokeapi.co/api/v2/generation/3
These are dont have pokemon informations. It has pokemon-species information. https://pokeapi.co/api/v2/pokemon/1 and https://pokeapi.co/api/v2/pokemon-species/1 are different. For this project I continued with pokemon lists directly, not generation responses.
-
Create .env file
cp .env.example .env
-
Edit
.env
file and set necessary fields:MONGODB_URI
,APP_PORT
andJWT_SECRET_KEY
-
Run npm install both backend&frontend
cd backend npm install
and for the frontend:
cd frontend npm install
Open two terminal on for backend and the other for frontend
- Run the application
cd backend
npm start
Run the application
cd frontend
npm start
- Backend
- "bcryptjs"
- "cors"
- "dotenv"
- "express"
- "express-validator"
- "jsonwebtoken"
- "mongoose"
- "nodemon"
- Frontend
- "angular"
- "rxjs"
-
/poke/register
- Data is validating =>
user.validator.js
- Password hashing =>
bcrypt
- If its successfull redirects to login, Otherwise returns error messages.
- Data is validating =>
-
/poke/login
- Checks given email and hashed password
- If login successful returns
token
. - On the browser after successful login,
jwt
andemail
is writing to thelocalStorage
. - Active
Interceptor Provider
adds token to theAuthorization Header
- Stricted pages are covering with
auth.guard
. It checks is user logged in. auth.service
is checking localstorage and validates jwt.- Also there is no endpoint for
logout
butauth.service
haslogout
and it removesjwt
from thelocalStorage
.
Pokemons
are guarded by AuthGuard
on app-routing.module.ts
. User has to login, otherwise they are not able to see the screen.
/poke/update
- Fetchs all pokemon informations from external api by given generation number from user.
- Collects all pokemon urls and makes http request all of them.
- Stores all pokemons in a variable.
- Save all of them in a loop.
/poke/generation
- User select generation from dropdown and pokemons will be display.
/poke/type
- User select type from dropdown and pokemons will be display.
/poke/random
- After clicking the "Get Shiny" button random shiny pokemon will be display.
-
users
- id
- password
-
pokemons
- id
- id_value
- generation
- name
- type
- image
- shiny_image