S52 Capstone 2 Added
parent
46a2e16bef
commit
ee9419584f
@ -1,140 +1,176 @@
|
|||||||
> Run: npm start
|
## E-COMMERCE API DOCUMENTATION
|
||||||
|
|
||||||
**** Stretch Goals ****
|
**_INSTALLATION COMMAND:_**
|
||||||
+ Set user as Admin ( Admin Only )
|
|
||||||
+ Retrieve Authenticated User's Orders
|
`npm install bcrypt cors dotenv express faker jsonwebtoken mongoose nodemon`
|
||||||
+ Retrieve all orders ( Admin Only )
|
|
||||||
+ Add to Cart ( Added Products, Change Product Quantities, Remove Products From Cart, Subtotal for each item, Total price for all items)
|
**_Start_**
|
||||||
+ Authentication Token with expiration (1hr)
|
npm start
|
||||||
+ dotenv
|
|
||||||
+ faker (Auto Generate Names)
|
**_TEST ACCOUNTS:_**
|
||||||
+ getUserDetails function ( Detects if the user tries to get the details of the other useId's + Token auth)
|
|
||||||
+ Middleware Secure verification that match Token and UserId to next()
|
- Regular User:
|
||||||
|
- email: user@email.com
|
||||||
**** Accounts ****
|
- pwd: user
|
||||||
|
- Admin User:
|
||||||
User: ( Password: wapatu )
|
- email: admin@email.com
|
||||||
{
|
- pwd: admin
|
||||||
"userId": "65544d9be5c01f6c0ca79200",
|
|
||||||
"email": "wapatu@example.com",
|
**_ROUTES:_**
|
||||||
"firstName": "Estevan",
|
|
||||||
"lastName": "Cummings",
|
- User registration (POST)
|
||||||
"isAdmin": false,
|
- http://localhost:3000/user/register
|
||||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NTU0NGQ5YmU1YzAxZjZjMGNhNzkyMDAiLCJlbWFpbCI6IndhcGF0dUBleGFtcGxlLmNvbSIsImlzQWRtaW4iOmZhbHNlLCJpYXQiOjE3MDAwMjM3MjQsImV4cCI6MTcwMDAyNzMyNH0.dpWV9Zx64TH4RLgmV_RlyrMBCa0HwDe9wJRAkwAyjys"
|
- auth header required: NO
|
||||||
}
|
- request body:
|
||||||
|
{
|
||||||
Admin: (Password is: admin )
|
"email": "admin@email.com",
|
||||||
{
|
"password": "admin"
|
||||||
"userId": "65535cb526b586a3e2fd56cc",
|
}
|
||||||
"email": "admin@email.com",
|
|
||||||
"isAdmin": true,
|
- User authentication (POST)
|
||||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NTUzNWNiNTI2YjU4NmEzZTJmZDU2Y2MiLCJlbWFpbCI6ImFkbWluQGVtYWlsLmNvbSIsImlzQWRtaW4iOnRydWUsImlhdCI6MTcwMDAyMzgxMSwiZXhwIjoxNzAwMDI3NDExfQ.DrhpNlBJKpfHod7MfTalQ5j2-s8tnR630yh2-_EIYWw"
|
- http://localhost:3000/user/login
|
||||||
}
|
- auth header required: NO
|
||||||
|
- request body:
|
||||||
**** Links ****
|
{
|
||||||
|
"email": "admin@email.com",
|
||||||
REGISTER
|
"password": "admin"
|
||||||
http://localhost:3000/user/register
|
}
|
||||||
--> Use post
|
|
||||||
{
|
- Create Product (Admin only) (POST)
|
||||||
"email": "admin@email.com",
|
- http://localhost:4000/product/create
|
||||||
"password": "admin"
|
- auth header required: YES
|
||||||
}
|
- request body:
|
||||||
|
{
|
||||||
LOGIN
|
"name": "Poring Card",
|
||||||
http://localhost:3000/user/login
|
"description": "Description unknown",
|
||||||
--> Use post
|
"price": 500
|
||||||
{
|
}
|
||||||
"email": "admin@email.com",
|
|
||||||
"password": "admin"
|
- Update Profile
|
||||||
}
|
- http://localhost:3000/user/update
|
||||||
|
- auth header required: YES
|
||||||
UPDATE PROFILE
|
- request body:
|
||||||
http://localhost:3000/user/update
|
{
|
||||||
--> Must use Admin token // use put
|
"userId": "",
|
||||||
{
|
"newEmail": "",
|
||||||
"userId": "6554473388d9942bbf4de065",
|
"newFirstname": "",
|
||||||
"newEmail": "mundo@email.com",
|
"newLastName": "",
|
||||||
"newFirstname": "Ron",
|
"newPassword": ""
|
||||||
"newLastName": "Pogi",
|
}
|
||||||
"newPassword": "mundo"
|
|
||||||
}
|
- Retrieve all products (Admin only) (GET)
|
||||||
|
- http://localhost:3000/product/all
|
||||||
CREATE PRODUCT [ADMIN]
|
- auth header required: YES
|
||||||
http://localhost:3000/user/products
|
- request body: none
|
||||||
--> Must use Admin token // use post
|
|
||||||
{
|
- Retrieve all active products (GET)
|
||||||
"name": "Poring Card",
|
- http://localhost:3000/product/active
|
||||||
"description": "Description unknown",
|
- auth header required: NO
|
||||||
"price": 500
|
- request body: none
|
||||||
}
|
|
||||||
|
- Get all products (GET)
|
||||||
GET ALL PRODUCT
|
- http://localhost:3000/product/active
|
||||||
http://localhost:3000/user/all
|
- auth header required: NO
|
||||||
--> Use get
|
- request body: none
|
||||||
|
|
||||||
GET ALL ACTIVE PRODUCT
|
- Get a product (GET)
|
||||||
http://localhost:3000/user/active
|
- http://localhost:3000/product/products/65545a1e6fa9d841e1518d1d
|
||||||
--> Use get
|
- auth header required: YES
|
||||||
|
- request body: none
|
||||||
GET A SINGLE PROUCT
|
|
||||||
http://localhost:3000/user/products/65538bd4a601aa30730f6d4c
|
- Update Single product (PUT)
|
||||||
--> Use get
|
- http://localhost:3000/product/products/65545a1e6fa9d841e1518d1d
|
||||||
|
- auth header required: YES
|
||||||
UPDATE A PRODUCT [ADMIN]
|
- request body:
|
||||||
http://localhost:3000/user/products/65545a1e6fa9d841e1518d1d
|
{
|
||||||
--> Must use Admin token // Use put
|
"name": "Christmas Cookie Card",
|
||||||
{
|
"description": "Updated Product Description",
|
||||||
"name": "Christmas Cookie Card",
|
"price": 29.99,
|
||||||
"description": "Updated Product Description",
|
"isActive": false
|
||||||
"price": 29.99,
|
}
|
||||||
"isActive": false
|
|
||||||
}
|
- Create Order (POST)
|
||||||
|
- http://localhost:3000/user/order
|
||||||
ACTIVATE / ARCHIVE A PRODUCT [ADMIN]
|
- auth header required: YES
|
||||||
--> Use Put
|
- request body:
|
||||||
http://localhost:3000/user/products/6554634e5cac4bcd6f2394ed/activate
|
{
|
||||||
http://localhost:3000/user/products/6554634e5cac4bcd6f2394ed/archive
|
"userId": "65535cb526b586a3e2fd56cc", // Replace with a valid user ID from your database
|
||||||
|
"products": [
|
||||||
|
{
|
||||||
RETRIEVE OWN USER DATA
|
"productId": "6553a4e897ac8ac9462f96c4", // Replace with a valid product ID from your database
|
||||||
--> Use Get
|
"productName": "Mastering Card",
|
||||||
http://localhost:3000/user/retrieveUser
|
"quantity": 1
|
||||||
{
|
}
|
||||||
|
],
|
||||||
"userId": "6554ac8dd7fbf9ee90217e77"
|
"totalAmount": 500
|
||||||
}
|
}
|
||||||
|
|
||||||
CART - Add to Cart
|
|
||||||
--> Must use token
|
- Activate / Archive Product (PUT)
|
||||||
http://localhost:3000/cart/add-to-cart
|
- auth header required: YES
|
||||||
{
|
- request body: none
|
||||||
"userId": "655396dcc8ea29f42422e214",
|
- http://localhost:3000/product/products/6554634e5cac4bcd6f2394ed/activate
|
||||||
"productId": "6553a54566c4c86c39034b55",
|
- http://localhost:3000/product/products/6554634e5cac4bcd6f2394ed/archive
|
||||||
"quantity": 5
|
|
||||||
}
|
- Set User to Admin (POST) [Admin Only]
|
||||||
|
- hhttp://localhost:3000/user/set-admin/
|
||||||
CART - Delete Item
|
- auth header required: YES
|
||||||
http://localhost:3000/cart/remove-from-cart
|
- request body:
|
||||||
--> Must use token
|
{
|
||||||
{
|
"userId":
|
||||||
"userId": "655396dcc8ea29f42422e214",
|
}
|
||||||
"productId": "6553a55666c4c86c39034b59",
|
|
||||||
"quantity": 1
|
- Retrieve All Orders [Admin Only] (GET)
|
||||||
}
|
- http://localhost:3000/user/orders-all
|
||||||
|
- auth header required: YES
|
||||||
CART - Update Quantity
|
- request body: none
|
||||||
http://localhost:3000/cart//update-quantity
|
|
||||||
--> Must use token
|
- Add To Cart (POST)
|
||||||
{
|
- http://localhost:3000/cart/add-to-cart
|
||||||
"userId": "655396dcc8ea29f42422e214",
|
- auth header required: YES
|
||||||
"productId": "6553a55666c4c86c39034b59",
|
- request body:
|
||||||
"quantity": 2000 // Update to the desired quantity
|
{
|
||||||
}
|
"userId": "655396dcc8ea29f42422e214",
|
||||||
|
"productId": "6553a54566c4c86c39034b55",
|
||||||
CART - Cart Details [ Total ]
|
"quantity": 5
|
||||||
--> Must use token
|
}
|
||||||
http://localhost:3000/cart/cart-details
|
|
||||||
{
|
- Delete Item (DELETE)
|
||||||
"userId": "655396dcc8ea29f42422e214"
|
- http://localhost:3000/cart/remove-from-cart
|
||||||
}
|
- auth header required: YES
|
||||||
|
- request body:
|
||||||
|
{
|
||||||
|
"userId": "655396dcc8ea29f42422e214",
|
||||||
|
"productId": "6553a54566c4c86c39034b55",
|
||||||
|
"quantity": 5
|
||||||
|
}
|
||||||
|
|
||||||
|
- Update Quantity (PUT)
|
||||||
|
- http://localhost:3000/cart//update-quantity
|
||||||
|
- auth header required: YES
|
||||||
|
- request body:
|
||||||
|
{
|
||||||
|
"userId": "655396dcc8ea29f42422e214",
|
||||||
|
"productId": "6553a55666c4c86c39034b59",
|
||||||
|
"quantity": 2000
|
||||||
|
}
|
||||||
|
|
||||||
|
- Cart Total (GET)
|
||||||
|
- http://localhost:3000/cart/cart-details
|
||||||
|
- auth header required: YES
|
||||||
|
- request body:
|
||||||
|
{
|
||||||
|
"userId": "655396dcc8ea29f42422e214"
|
||||||
|
}
|
||||||
|
|
||||||
|
\***\* Stretch Goals \*\***
|
||||||
|
|
||||||
|
- Set user as Admin ( Admin Only )
|
||||||
|
- Retrieve Authenticated User's Orders
|
||||||
|
- Retrieve all orders ( Admin Only )
|
||||||
|
- Add to Cart ( Added Products, Change Product Quantities, Remove Products From Cart, Subtotal for each item, Total price for all items)
|
||||||
|
- Authentication Token with expiration (1hr)
|
||||||
|
- dotenv
|
||||||
|
- faker (Auto Generate Names)
|
||||||
|
- getUserDetails function ( Detects if the user tries to get the details of the other useId's + Token auth)
|
||||||
|
- Middleware Secure verification that match Token and UserId to next()
|
||||||
|
Loading…
Reference in New Issue