/poke-shop

Project for testing my development skills

Primary LanguageJavaScriptMIT LicenseMIT

poke-shop

Code test for Publicista.

This is a project for testing my development skills

Testing

A live example can be found at poke-shop.now.sh/graphiql

There you can try the graphql endpoint

You can try the test queries and see how the api works

You can still download and run the application on your machine, but do not forget to create a .env file in the root of the project like so:

PAYMENT_API='https://api.pagar.me/1/transactions'
PAYMENT_API_KEY='YOUR_PAGARME_API_KEY'
MLAB_USER='user'
MLAB_PASSWORD='password'
MLAB_ENDPOINT='ENDPOINT.mlab.com:PORT'
MLAB_DATABASE='DATABASE_NAME'

For the buy operations you will need to provide credit card information

You can use any valid fake credit card like the generated by 4devs

Although I do not store any credit card info I strongly recommend you do not use any real credit card info on the Live demo.

Here are some fake data to input on the "Query variables":

{
  "pokemon": {
    "name": "blastoise",
    "price": 100000,
    "stock": 10
  },
  "bulba": "bulbasaur",
  "charmander": "charmander",
  "creditCard": {
    "card_number": "4024007187545495",
    "card_expiration_date": "0719",
    "card_holder_name": "Ash Ketchum",
    "card_cvv": "825"
  },
  "wrongCreditCard": {
    "card_number": "0000007187540000",
    "card_expiration_date": "0102",
    "card_holder_name": "Ash Ketchup",
    "card_cvv": "123"
  }
}

Enhancements made

Some improvements I made over the previous "bad code" are:

  • GraphQL instead of REST endpoint
    • This allow for a better control and flexibility on the client side
    • For more opinions on the matter you can look here or here
  • Separation of conserns and structuring the application
    • Mongorito on top of MongoDB allows to put all models operations in their corresponding models
    • Relying on environment variables allows for development flexibility and server instantiation scalability, and also more security as no sensitive data needs to be put on the code base
    • Separating different parts of the application in different files and in a clear folder structure allows better maintainability and application grow
    • Utilizing nodemon allows the development to be more fluid
  • A restock action was put into the application
  • Some extra validation was made to ensure all needed data is passed