Giter Club home page Giter Club logo

valex-backend's Introduction

JavaScriptLogo

Valex

18th Project of Driven Education
An API Project to manage benefit cards

Built With

Project Guide

Features

  • Get the card balance and transactions
  • Create cards
  • Activate / Block / Unlock a card
  • Recharge a card
  • Make card payments with online payment option

API Reference

TL;DR
POST /cards/create

Header:

{
    "x-api-key": string
}

Body:

{
    "employeeId": integer,
    "cardType": string
}

Response:

{   
    "cardId": 1,
	"number": "1111 1111 1111 1111",
	"cardholderName": "NAME N NAME",
	"creditCardCVC": "111",
	"expirationDate": "01/27",
}
PATCH /cards/activate Body:
{
    "employeeId": integer,
    "secutiryCode": string,
    "password": string
}
POST /cards/recharge

Header:

{
    "x-api-key": string
}

Body:

{
    "cardId": integer,
    "value": integer,
}
PATCH /cards/block

Body:

{
    "cardId": integer,
    "password": string
}
PATCH /cards/unlock

Body:

{
    "cardId": integer,
    "password": string
}
GET /cards/statement/:cardId

Params:

{
    "cardId": integer
}
POST /purchases/pos/:cardId

Body:

{
    "cardId": integer,
    "businessId": integer,
    "cardPassword": string,
    "value": integer 

    // value: use 4000 instead of 40.00 
}

Create a card

POST /cards/create

Request:

Body Type Description
employeeId integer Required. user Id
cardType string Required. type of card benefit

Valid types: [groceries, restaurant, transport, education, health]

Headers Type Description
x-api-key string Required. api key


Response:

{   
    "cardId": 1,
	"number": "1111 1111 1111 1111",
	"cardholderName": "NAME N NAME",
	"creditCardCVC": "111",
	"expirationDate": "01/27",
}

Activate a card

PATCH /cards/activate

Request:

Body Type Description
employeeId integer Required. employeeId
securityCode string Required. card cvv
password string Required. card password

Password length: 4

Password pattern: only numbers

CVV max length: 3

CVV pattern: only numbers

Recharge a card

POST /cards/recharge

Request:

Headers Type Description
x-api-key string Required. api key

Body Type Description
cardId integer Required. card Id
value integer Required. recharge amount

Block a card

PATCH /cards/block

Request:

Body Type Description
cardId integer Required. card Id
password string Required. card password

Password length: 4

Password pattern: only numbers

Unlock a card

PATCH /cards/unlock

Request:

Body Type Description
cardId integer Required. card Id
password string Required. card password

Password length: 4

Password pattern: only numbers

Get card balance

GET /cards/statement/:cardId

Request:

Params Type Description
cardId integer Required. card Id

Response:

{
"balance": 35000,
"transactions": [
{ "id": 1, "cardId": 1, "businessId": 1, "businessName": "DrivenEats", "timestamp": "22/01/2022", "amount": 5000 },{...},{...}
],
"recharges": [
{ "id": 1, "cardId": 1, "timestamp": "21/01/2022", "amount": 40000 },{...},{...}
]
}

Card payments

POST /purchases/pos/

Request:

Body Type Description
cardId integer Required. cardId
businessId integer Required. card expiration date
cardPassword string Required. card password
value integer Required. payment value

Value: must be without period, like '4000' instead of '40.00'

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

DATABASE_URL = postgres://YOUR-USER-NAME:YOUR-PASSWORD@Hostname:5432/DatabaseName

PORT = number

CRYPTR_SECRET = any string

Run Locally

Clone the project

  git clone https://github.com/DarlonGomes/projeto18-valex

Go to the project directory

  cd projeto18-valex/

Install dependencies

  npm install

Create database

  cd valex-setup/
  bash ./create-database
  cd ../../..

Start the server

  npm run start

Lessons Learned

  • API Architecture
  • TypeScript interfaces
  • TypeScript types
  • Classes
  • Constructor
  • Object Literals

Acknowledgements

Authors

  • Darlon Gomes is a student at Driven Education and is putting effort into switch careers. Nowadays he works with Fine Woodworking looking forward to become a Fullstack Dev.

valex-backend's People

Contributors

darlongomes avatar

Stargazers

William Eiji Fujimori avatar Lucas Palharini avatar Mary Karakida avatar Guilherme de Oliveira avatar Emily Nakano avatar Arthur Akira avatar Arthur Alcantara avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.