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