An API to generate and validate coupon codes
- Nodejs
- PostgreSQL
- Sequelize
- Users can
- Sign up
- Sign in
- Generate coupons
- Validate coupons
To run this API locally simply follow the instructions below:
You need to have or install the following:
- Git bash
- Npm
- Postman
-
clone repo
git clone https://github.com/fegoworks/coupon-validator.git
-
navigate to api folder
-
run installation
npm install
-
create a
.env
file with this templateDATABASE_URL_DEVELOPMENT='Your postgres development database url' DATABASE_URL_TEST='Your postgres test database url' DATABASE_URL= 'Your postgres production url' SECRET = 'Your secret phrase'
-
start app
npm run start:dev
-
you can now make requests using postman to
localhost:3000/api/v1/
To run tests simply run the following command in your git bash or command line
npm run test
Heroku: Coupon-API Documentation: Coupon-API-Docs
Endpoints | Functionality |
---|---|
POST /auth/create-user | Create new user account |
POST /auth/signin | Login a user |
POST /coupons/generate | Generate a coupon code |
POST /coupons/validate | Validate coupon code |
GET /coupons/ | View all coupon codes |
GET /coupons/flat | View flat discount coupon codes |
GET /coupons/percent | View percent discount coupon codes |
Send a POST
request to /api/v1/auth/create-user
with the following JSON structure:
{
"firstName": "Sensei",
"lastName": "Saitama",
"email": "saitama@mail.com",
"password": "password"
}
POST
requests are restricted to only registered accounts.
Send a POST
request to /api/v1/auth/signin
, with the following:
{
"email": ,
"password":
}
When you signin you'll receive a Bearer token
. You'll need this token to send any request related to coupons.
Frow now on, every request described here will require you send the Bearer token
Send a POST
request to /api/v1/coupons/generate
, with the following:
{
"discount": 400.0,
"minimumAmount": 200.0,
"maximumAmount": 0,
"discountType": "flat",
"expiryDate": "June 27, 2020 15:45:00"
}
The above will generate a flat discount coupon
The
discount
field for a flat discount should be a distinct amount like this"500.00"
ThemaximumAmount
field is only necessary when generating a coupon that has a percent discount, so for flat discounts we can set this field to0
The
expiryDate
field will accept JavaScript Date strings in the following formatsMM/DD/YYYY
or DateTime formats likeJune 27, 2020 15:45:00
{
"discount": 40,
"minimumAmount": 0,
"maximumAmount": 10000.0,
"discountType": "percent",
"expiryDate": "June 27, 2020 15:45:00"
}
Note that unlike the flat discount coupons, the
discount
field for percent discount coupons accepts an integer. And theminimumAccount
field can be set to0
Send a POST
request to /api/v1/coupons/validate
, with the following:
{
"coupon": "wwXGgh",
"cartPrice": 5000.0
}
Send a GET
request to /api/v1/coupons
Send a GET
request to /api/v1/coupons/flat
or /api/v1/coupons/percent
Edafe Oghenefego @realFego