English
- Prepare the environment variables as follows
Variable name Obligatory Description Default PORT ❌ Port to listen to (listen) server api 3001 MONGO_URI ✔ Connection string to connect to MongoDb JWT_ACCESS_KEY ✔ Secret key, used in Json Web token (accessToken) JWT_REFRESH_KEY ✔ Secret key, used in Json Web token (refreshToken) CLOUDINARY_API_KEY ✔ Cloudinary API key to connect to image storage CLOUDINARY_API_SECRET ✔ Cloudinary API key (secret key) to connect to image storage CLOUDINARY_NAME ✔ Name of Storage Cloudinary for image storage
Vietnamese
- Chuẩn bị các biến môi trường như sau
Tên biến Bắt buộc Mô tả Mặc định PORT ❌ Port để listen (lắng nghe) server api 3001 MONGO_URI ✔ Connection string để kết nối tới MongoDb JWT_ACCESS_KEY ✔ Khóa bí mật (secret key), dùng trong Json Web token (accessToken) JWT_REFRESH_KEY ✔ Khóa bí mật (secret key), dùng trong Json Web token (refreshToken) CLOUDINARY_API_KEY ✔ Khóa key của API Cloudinary để kết nối với storage lưu trữ hình ảnh CLOUDINARY_API_SECRET ✔ Khóa key (secret key) của API Cloudinary để kết nối với storage lưu trữ hình ảnh CLOUDINARY_NAME ✔ Tên của Storage Cloudinary lưu trữ hình ảnh
English
Using technologies: NodeJS, Express, MongoDb, Mongoose, jwt-authentication, jwt-authorization, cloudinary
Server of an ecommerce website with 3 permissions:
- Admin (full control, can delete anything, in addition can view customer invoice details as well as statistics on everything of the store)
- Manager (also has the same rights as admin to be able to manage the store, but does not have the right to delete anything that the admin has not allowed)
- Customer (only has the right to view and buy goods, does not affect the APIs of higher rights (admin, manager)
Currently the server is still being updated with the necessary functions, the update will be regularly updated here. Thank you!
Vietnamese
Sử dụng các công nghệ: NodeJS, Express, MongoDb, Mongoose, jwt-authentication, jwt-authorization, cloudinary
Server của 1 trang web ecommerce với 3 quyền:
- Admin (toàn quyền thao tác, có thể delete bất cứ gì, ngoài ra có thể xem chi tiết hóa đơn khác hàng cũng như thống kê mọi thứ của cửa hàng)
- Manager (cũng có các quyền gần giống với admin để có thể quản lý store, tuy nhiên không có quyền xóa bất cứ gì mà admin chưa cho phép)
- Customer (chỉ có quyền xem và mua hàng, không tác động gì đến các API của quyền cao hơn (admin, manager)
Hiện tại server vẫn đang được tiếp tục update các chức năng cần thiết, phần cập nhật sẽ thường xuyên được update tại đây. Xin cảm ơn!
Register Account
-
POST: api/v1/register -- [content-type: application/json]
-
Request:
params type require firstName string true lastName string true email string true password string true avatar string false phone string true googleId string false facebookId string false status string false isAdmin boolean default false -
Response:
{
"_id": "62ff067d2a6f2d35b72be673",
"firstName": "Hai",
"lastName": "Nguyen",
"email": "a@gmail.com",
"isAdmin": false,
"createdAt": "2022-08-19T03:41:49.494Z",
"updatedAt": "2022-08-19T03:41:49.494Z",
"__v": 0,
}
Login Account
-
POST: api/v1/login -- [content-type: application/json]
-
Request:
params type require email string true password string true -
Response:
{
"_id": "62ff067d2a6f2d35b72be673",
"firstName": "Hai",
"lastName": "Nguyen",
"email": "a@gmail.com",
"isAdmin": false,
"createdAt": "2022-08-19T03:41:49.494Z",
"updatedAt": "2022-08-19T03:41:49.494Z",
"__v": 0,
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZmYwNjdkMmE2ZjJkMzViNzJiZTY3MyIsImFkbWluIjpmYWxzZSwiaWF0IjoxNjYwOTAwNDEyLCJleHAiOjE2NjA5MDA0NDJ9.eL8hG06zfvY_aIWfb6uMFtPccNcjj-NYfFpxYoE5v-k",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZmYwNjdkMmE2ZjJkMzViNzJiZTY3MyIsImFkbWluIjpmYWxzZSwiaWF0IjoxNjYwOTAwNDEyLCJleHAiOjE2NjA5MDE0MTJ9.Llr9MuSPvRRWhWON1AJnRMSFz457H1ucjWv-_zwWGwc"
}
==> refreshToken is saved in the returned cookie with the key refreshToken
Refresh Token
-
POST: api/v1/refresh -- [content-type: application/json]
-
Headers: [Cookie] : refreshToken
-
Request: null
-
Response:
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZmYwNjdkMmE2ZjJkMzViNzJiZTY3MyIsImFkbWluIjp0cnVlLCJpYXQiOjE2NjEyMjY1NzQsImV4cCI6MTY2MTIyNjg3NH0.MbnNR9XEA9UKiDbniZK8Uuoff4W7FlHNzTDowmYiETw"
}
Logout Account
-
POST: api/v1/logout -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: Null
-
Response:
{
"message": ""
}
Get All Users
-
GET: api/v1/user -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: Null
-
Response:
{
{
"Info user 1": ""
},
{
"Info user 2": ""
}
}
Get A User
-
GET: api/v1/user/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: Null
-
Response:
{
"Info user": ""
}
Add User
-
POST: api/v1/user -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require firstName string true lastName string true email string true password string true avatar string false phone string true googleId string false facebookId string false status string false isAdmin boolean default false -
Response:
{
"firstName": "Hai Test",
"lastName": "Nguyen",
"email": "d@gmail.com",
"password": "123",
"isAdmin": false,
"phone": "14522",
"_id": "630494af24f33a4ee5cc2340",
"createdAt": "2022-08-23T08:49:51.091Z",
"updatedAt": "2022-08-23T08:49:51.091Z",
"__v": 0
}
Update User
-
PUT: api/v1/user/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require firstName string true lastName string true email string true password string true avatar string false phone string true googleId string false facebookId string false status string false isAdmin boolean default false -
Response:
{
"message": ""
}
Delete User With Params
-
DELETE: api/v1/user/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
"message": ""
}
Delete User With Body
-
DELETE: api/v1/user -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require id string true -
Response:
{
"message": ""
}
Get All Categories
-
GET: api/v1/category -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
{
"Info cate 1": ""
},
{
"Info cate 2": ""
}
}
Get A Category
-
GET: api/v1/category/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
"Info cate": {
...,
"products": [
{
"infoProduct_1"
},
{
"infoProduct_2"
}
]
}
}
Add A Category
-
POST: api/v1/category -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require name string true image string true slug string false desc string false countProduct number false -
Response:
{
"infoCateNew": {}
}
Update A Category
-
PUT: api/v1/category":id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require name string true image string true slug string false desc string false countProduct number false -
Response:
{
"message": ""
}
Delete A Category With Params
-
DELETE: api/v1/category/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
"message": ""
}
Delete A Category With Body
-
DELETE: api/v1/category -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require _id string true -
Response:
{
"message": ""
}
Get All Products
-
GET: api/v1/product -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
"Info product 1": ""
}
Get A Product
-
GET: api/v1/product/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
"Info product": {}
}
Add A Product
-
POST: api/v1/product -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require name string true slug string false thumbnail string true desc string false videoid string false pictures string false quantity number true sold number default 0 price number false category string false pictures string false -
Response:
{
"infoProductNew": {}
}
Update A Product
-
PUT: api/v1/product:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request:
params type require name string true slug string false thumbnail string true desc string false videoid string false pictures string false quantity number true sold number default 0 price number false category string false pictures string false -
Response:
{
"message": ""
}
Delete A Product
-
DELETE: api/v1/product/:id -- [content-type: application/json]
-
Headers: [token] : Bearer {accessToken}
-
Request: null
-
Response:
{
"message": ""
}
Get All NewsOnTop
-
GET: api/v1/newstop -- [content-type: application/json]
-
Headers: null
-
Request: null
-
Response:
[
{
"_id": "631b08d63e4ad36bdc96e9d5",
"name": "The Nike ZoomX Vaporfly NEXT%",
"desc": "The Nike ZoomX Vaporfly NEXT% clears your path to record-breaking speed with a lighter design and faster feel than before. With more cushioning underfoot and reduced weight up top, the result is unprecedented energy return and comfort",
"thumbnail": "https://raw.githubusercontent.com/ThaiHaiDev/StoreImage/main/Sport_store/zoomx-vaporfly-next-running-shoe-4Q5jfG.png",
"bgColor": "blue",
"picture_item_1": "https://raw.githubusercontent.com/ThaiHaiDev/StoreImage/main/Sport_store/zoomx-vaporfly-next-running-shoe-4Q5jfG-1.jpg",
"picture_item_2": "https://raw.githubusercontent.com/ThaiHaiDev/StoreImage/main/Sport_store/zoomx-vaporfly-next-running-shoe-4Q5jfG (1).jpg",
"picture_item_3": "https://raw.githubusercontent.com/ThaiHaiDev/StoreImage/main/Sport_store/zoomx-vaporfly-next-running-shoe-4Q5jfG (2).jpg",
"picture_item_4": "https://raw.githubusercontent.com/ThaiHaiDev/StoreImage/main/Sport_store/zoomx-vaporfly-next-running-shoe-4Q5jfG (3).jpg",
"quantity": 100,
"sold": 0,
"price": 230,
"category": {
"_id": "6304e3a2d459b2475990df4a",
"name": "Nike",
"countProduct": 0,
"createdAt": "2022-08-23T14:26:42.318Z",
"updatedAt": "2022-09-07T15:32:52.468Z",
"slug": "nike",
"__v": 0,
"products": [
"630503ee1e2bdc547c326d62",
"63088e792bf82311dc905125",
"6318a84d4674de3e1fdaa633"
]
},
"views": 0,
"isOutOfStock": false,
"createdAt": "2022-09-09T09:35:18.251Z",
"updatedAt": "2022-09-09T09:35:18.251Z",
"slug": "the-nike-zoomx-vaporfly-next",
"__v": 0
},
]
Add NewsOnTop
- POST: api/v1/product -- [content-type: application/json]
- Headers: [token] : Bearer {accessToken}
- Request:
{
"name": "require",
"desc": "require",
"thumbnail": "require",
"bgColor": "require",
"picture_item_1": "require",
"picture_item_2": "require",
"picture_item_3": "require",
"picture_item_4": "require",
"quantity": "require number",
"price": "require number",
"category": "require",
"sold": "no require number",
"videoid": "no require",
"views": "no require number",
"isOutOfStock": "no require boolean"
}
- Response:
{
"name": "",
"desc": "",
"thumbnail": "",
"bgColor": "",
"picture_item_1": "",
"picture_item_2": "",
"picture_item_3": "",
"picture_item_4": "",
"quantity": 100,
"sold": 0,
"price": 230,
"category": "",
"views": 0,
"isOutOfStock": false,
"_id": "",
"createdAt": "2022-09-09T10:03:36.898Z",
"updatedAt": "2022-09-09T10:03:36.898Z",
"slug": "",
"__v": 0
}