owned this note
owned this note
Published
Linked with GitHub
###### 📋 Content:
[TOC]
# Authenticate
## Login
`POST /authentication/login`
Login sẽ trả về access_token:
- Request:
```json
{
"username": "user1@gmail.com",
"password": "randompass"
}
```
- Response:
```json
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI3YmQ4OWMwNC00NGUzLTRjMWEtYTk3YS0wMmEzM2ZjZjFhYjAiLCJ1c2VybmFtZSI6InJhbmRvbW5hbWUiLCJyb2xlcyI6IkNVU1RPTUVSIiwiaWF0IjoxNzMwNDc5MTczLCJleHAiOjE3MzEwODM5NzN9.u0YMxH_WCzKw49F9iYAZ00aI7Ms-OwQY8TDRoIaqkg4"
}
```
## Sign up
`POST /authentication/signup`
- Request:
```json
{
"email": "user1@gmail.com",
"phone_number": "0987633234",
"full_name": "randomname",
"password": "randompass"
}
```
- Response:
```
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI3YmQ4OWMwNC00NGUzLTRjMWEtYTk3YS0wMmEzM2ZjZjFhYjAiLCJ1c2VybmFtZSI6InJhbmRvbW5hbWUiLCJyb2xlIjoiQ1VTVE9NRVIiLCJpYXQiOjE3MzA0NzkxNjgsImV4cCI6MTczMTA4Mzk2OH0.HRfLbmX6E0_NllIgSLfW6JweU1s32Eh1fxe8fSqXUao"
}
```
## Get profile
`GET /authentication/profile`
Header : Brearer token
Request:
Response:
```
{
"id": "338decaa-ca84-476b-a385-db292fe3d93e",
"avatar": null,
"full_name": "admin",
"phone_number": "0987654321",
"address": null,
"email": "admin@gmail.com",
"role": "CUSTOMER",
"is_valid": true,
"create_at": "2024-11-01T16:26:35.492Z"
}
```
# User
## Get all profile
`GET /users/getUsers`
Header : Brearer token
Request:
```query (optional)
Example:
* /users/getUsers
* /users/getUsers?page=1&limit=20&sortBy=id:DESC
* /users/getUsers?filter.branch_id=branch2
* /users/getUsers?filter.full_name=$gte:anhledger&filter.branch_id=branch2&sortBy=id:ASC
```
Response:
```
{
"data": [
{
"id": "fc02cfff-c75b-4cb3-b5bd-11f6629cf1e4",
"avatar": null,
"full_name": "adminvippro",
"phone_number": "0796688018",
"address": null,
"email": "admin@gmail.com",
"role": "ADMIN",
"hash_password": "$2b$10$ivdxPv7e.UG4ZP8ocPd7w.na8QwDQWsVuinIL14bfOb3HRgXdKcgC",
"is_valid": true,
"create_at": "2024-11-07T21:00:46.116Z"
},
{
"id": "e8b550f9-7dc3-4975-8b74-b41dba937d84",
"avatar": null,
"full_name": "Nguyen Van B",
"phone_number": "0987654332",
"address": null,
"email": "email1@gmail.com",
"role": "CUSTOMER",
"hash_password": "$2b$10$hkDikLP.kK0urtsslcKROOtOhCuxWyvsKxbH/dL7MD6pOAEbUwpNW",
"is_valid": true,
"create_at": "2024-11-02T05:32:20.570Z"
},
{
"id": "465fb72b-2043-4faf-8ef8-8ff20f5134b0",
"avatar": null,
"full_name": "anhledger",
"phone_number": "0987653234",
"address": null,
"email": "anhledger@example.com",
"role": "CUSTOMER",
"hash_password": "$2b$10$jSH9wGON56XWRezTGHpa5./2EJQ.gyRj2FMRQTHBl891x8D0XAMf2",
"is_valid": true,
"create_at": "2024-11-03T10:00:41.946Z"
}
],
"meta": {
"itemsPerPage": 20,
"totalItems": 3,
"currentPage": 1,
"totalPages": 1,
"sortBy": [
[
"id",
"DESC"
]
]
},
"links": {
"current": "http://localhost:3000/users/getAll?page=1&limit=20&sortBy=id:DESC"
}
}
```
## Update list users
`Put /users/updateList`
Header : Brearer token
Request:
```
[
{
"id": "e8b550f9-7dc3-4975-8b74-b41dba937d84",
"phone_number": "0987654332",
"full_name": "Nguyen Van B"
},
{
"id": "465fb72b-2043-4faf-8ef8-8ff20f5134b0",
"full_name": "anhledger",
"phone_number": "0987653224",
"email": "anhledger@example.com",
"hash_password": "anhledger",
"role": "ADMIN"
}
]
```
Response:
```HttpStatus```
# Menu item
Đây là menu tổng, những chi nhánh chỉ được chọn ở đây chứ không tự tạo.
Tạm thời chưa gán quyền, cho tiện
## Get list
`GET /menu-items`
Query:
- `sortBy`: `id:DESC`
...
Những query khác thêm rất nhanh nên nếu có nhu cầu thì ping phát.
Request:
`GET /menu-items?sortBy=id:DESC`
:::spoiler Response
```json
{
"data": [
{
"id": "bunbo",
"item_name": "Bún cha xả giao",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/0/00/Bun-Bo-Hue-from-Huong-Giang-2011.jpg",
"item_type": 2,
"description": "Mô tả sơ về bún bò",
"price": 30000,
"create_at": "2024-11-01T17:01:45.517Z"
}
],
"meta": {
"itemsPerPage": 20,
"totalItems": 1,
"currentPage": 1,
"totalPages": 1,
"sortBy": [
[
"id",
"DESC"
]
]
},
"links": {
"current": "http://pbl6-cats-pbl6-informative-system.hf.space/menu-items?page=1&limit=20&sortBy=id:DESC"
}
}
```
:::
## Add menu item
Tạo một món mới trong menu tổng
`POST /menu-items`
:::spoiler Request
```json
{
"id": "bunbo",
"item_name": "Bún cha xả giao",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/0/00/Bun-Bo-Hue-from-Huong-Giang-2011.jpg",// optional
"description": "Mô tả sơ về bún bò",
"item_type": "monchinh",
"price": 30000
}
```
:::
:::spoiler Response
```json!
{
"id": "bunbo",
"item_name": "Bún cha xả giao",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/0/00/Bun-Bo-Hue-from-Huong-Giang-2011.jpg",
"item_type": "monchinh",
"description": "Mô tả sơ về bún bò",
"price": 30000,
"create_at": "2024-11-01T17:01:45.517Z"
}
```
:::
## Update menu item
`PATCh /menu-items/:id`
Update một phần, giống y như create trừ cái id ra.
vd: `PATCH /menu-items/bunbo`
# Feeds - Bài đăng
## Lấy danh sách
`GET /feeds`
Cũng có query, paginate như trên list menu
:::spoiler Response
```json!
{
"data": [
{
"id": 1,
"author_id": null,
"image_url": "https://i2.ex-cdn.com/crystalbay.com/files/content/2024/08/15/bun-bo-hue-2-0933.jpg",
"title": "Bún bò huế",
"description": "Bún bò Huế là một món ăn đặc sản nổi tiếng của thành phố Huế, miền Trung Việt Nam. Đây là một món bún nước có hương vị đậm đà, đặc trưng bởi nước dùng được nấu từ xương bò và giò heo, kết hợp với sả, mắm ruốc, và ớt, tạo nên hương thơm nồng nàn và vị cay nhẹ. Thịt bò thái lát mỏng, giò heo, chả cua, huyết heo, và các loại rau thơm như húng quế, rau răm, giá đỗ được dùng kèm, làm tăng độ phong phú của món ăn.",
"create_at": "2024-11-01T17:12:42.220Z"
}
],
"meta": {
"itemsPerPage": 20,
"totalItems": 1,
"currentPage": 1,
"totalPages": 1,
"sortBy": [
[
"id",
"DESC"
]
]
},
"links": {
"current": "http://pbl6-cats-pbl6-informative-system.hf.space/feeds?page=1&limit=20&sortBy=id:DESC"
}
}
```
:::
## Add feed
`POST /feeds`
:::spoiler Request
```json!
{
"image_url":"https://i2.ex-cdn.com/crystalbay.com/files/content/2024/08/15/bun-bo-hue-2-0933.jpg",
"title": "Bún bò huế",
"description": "Bún bò Huế là một món ăn đặc sản nổi tiếng của thành phố Huế, miền Trung Việt Nam. Đây là một món bún nước có hương vị đậm đà, đặc trưng bởi nước dùng được nấu từ xương bò và giò heo, kết hợp với sả, mắm ruốc, và ớt, tạo nên hương thơm nồng nàn và vị cay nhẹ. Thịt bò thái lát mỏng, giò heo, chả cua, huyết heo, và các loại rau thơm như húng quế, rau răm, giá đỗ được dùng kèm, làm tăng độ phong phú của món ăn."
}
```
:::
:::spoiler Response
```json!
{
"image_url": "https://i2.ex-cdn.com/crystalbay.com/files/content/2024/08/15/bun-bo-hue-2-0933.jpg",
"title": "Bún bò huế",
"description": "Bún bò Huế là một món ăn đặc sản nổi tiếng của thành phố Huế, miền Trung Việt Nam. Đây là một món bún nước có hương vị đậm đà, đặc trưng bởi nước dùng được nấu từ xương bò và giò heo, kết hợp với sả, mắm ruốc, và ớt, tạo nên hương thơm nồng nàn và vị cay nhẹ. Thịt bò thái lát mỏng, giò heo, chả cua, huyết heo, và các loại rau thơm như húng quế, rau răm, giá đỗ được dùng kèm, làm tăng độ phong phú của món ăn.",
"author_id": null,
"id": 1,
"create_at": "2024-11-01T17:12:42.220Z"
}
```
:::
## Update feed
`PATCH /feeds/:id`
:::spoiler Request
`Patch /feeds/1`
```json!
{
"title": "Mỳ Bò Khoa",
"description": "Bỏ đi cái phần dài dòng"
}
```
:::
:::spoiler Response
```json!
{
"id": 1,
"author_id": null,
"image_url": "https://i2.ex-cdn.com/crystalbay.com/files/content/2024/08/15/bun-bo-hue-2-0933.jpg",
"title": "Mỳ Bò Khoa",
"description": "Bỏ đi cái phần dài dòng",
"create_at": "2024-11-01T17:12:42.220Z"
}
```
:::
# Branch - chi nhánh
## Create branch - tạo chi nhánh mới
Phương thức chỉ có Admin được gọi
`POST /branchs`
:::spoiler Request
```json!
{
"id": "branch1",
"name":"Branch1",
"location":"Pham nhu xuong",
"phone_number": "0796688018"
}
```
:::
:::spoiler Response
```json
{
"id": "branch1",
"name": "Branch1",
"image_url": null,
"location": "Pham nhu xuong",
"phone_number": "0796688018",
"create_at": "2024-11-01T15:25:21.573Z"
}
```
:::
## Update branch
Phương thức chỉ có Admin, quản lý branch và quản lý area
`Patch /branchs/:branchId`
Tương tự như khi tạo
:::spoiler Request
```json!
{
"name":"Branch1", // optional
"image_url":"https://image.url" // optional
"location":"Pham nhu xuong", // optional
"phone_number": "0796688018" // optional
}
```
:::
:::spoiler Response
```json
{
"id": "branch1",
"name": "Branch1",
"location": "Pham nhu xuong",
"phone_number": "0796688018",
"create_at": "2024-11-01T17:24:13.867Z"
}
```
:::
## Get branch list
Lấy danh sách branch thì ai cũng có thể gọi
`GET /branchs`
Lần này thì list thật, không có pagination như trên
## Get a branch
`GET /branchs/branch1`
## Get manage branch list
`GET branchs/manage`
# Branch menu - quản lý menu cho chi nhánh
## Get branch menu list
Lưu ý rằng branch menu list cấu trúc trả về và query sẽ khác một chút với menu.
:::spoiler Request
`GET {{domain}}/branchs/branch1/menus?filter.menu_item.item_type=1&limit=3`
:::
:::spoiler Response
```json
{
"data": [
{
"id": "466ceb3d-71bd-4b1d-a531-63643b69eab4",
"branch_id": "branch1",
"menu_id": "pho",
"description": "Món phở truyền thống với nước dùng thanh ngọt",
"is_open": true,
"sold_count": 0,
"menu_item": {
"id": "pho",
"item_name": "Phở bò",
"image_url": "https://cdn.tgdd.vn/Files/2017/03/18/962092/an-lien-3-bat-pho-voi-cong-thuc-nau-pho-nay-202201261419401397.jpg",
"item_type": 1,
"description": "Món phở truyền thống với nước dùng thanh ngọt",
"price": 35000,
"create_at": "2024-11-02T13:42:02.009Z"
}
},
{
"id": "11ba1622-41da-453b-a38a-29e817d046ed",
"branch_id": "branch1",
"menu_id": "buncha",
"description": "Món bún nổi tiếng Hà Nội với thịt nướng thơm ngon",
"is_open": true,
"sold_count": 0,
"menu_item": {
"id": "buncha",
"item_name": "Bún chả",
"image_url": "https://kipor.vn//upload/images/lam-bun-cha-bang-noi-chien-khong-dau-6.jpg",
"item_type": 1,
"description": "Món bún nổi tiếng Hà Nội với thịt nướng thơm ngon",
"price": 40000,
"create_at": "2024-11-02T13:42:02.009Z"
}
},
{
"id": "000d363d-d133-41a1-a000-fddd260de3b3",
"branch_id": "branch1",
"menu_id": "cakho",
"description": "Cá kho trong nồi đất với hương vị đậm đà",
"is_open": true,
"sold_count": 0,
"menu_item": {
"id": "cakho",
"item_name": "Cá kho tộ",
"image_url": "https://khaihoanphuquoc.com.vn/wp-content/uploads/2023/05/thanh-pham.png",
"item_type": 1,
"description": "Cá kho trong nồi đất với hương vị đậm đà",
"price": 70000,
"create_at": "2024-11-02T13:42:02.009Z"
}
}
],
"meta": {
"itemsPerPage": 3,
"totalItems": 12,
"currentPage": 1,
"totalPages": 4,
"sortBy": [
[
"menu_item.item_type",
"ASC"
]
],
"filter": {
"menu_item.item_type": "1"
}
},
"links": {
"current": "http://pbl6-cats-pbl6-informative-system.hf.space/branchs/branch1/menus?page=1&limit=3&sortBy=menu_item.item_type:ASC&filter.menu_item.item_type=1",
"next": "http://pbl6-cats-pbl6-informative-system.hf.space/branchs/branch1/menus?page=2&limit=3&sortBy=menu_item.item_type:ASC&filter.menu_item.item_type=1",
"last": "http://pbl6-cats-pbl6-informative-system.hf.space/branchs/branch1/menus?page=4&limit=3&sortBy=menu_item.item_type:ASC&filter.menu_item.item_type=1"
}
}
```
:::
## Add a branch menu
- Thêm một item trong menu vào branch
`POST /branchs/:branchId/menus`
:::spoiler Request
```json!
{
"menu_id": "bunbo",
"description":"Empty cungx duoc" // nếu không có thì sẽ lấy nguyên từ menu gốc
}
```
:::
:::spoiler Response
```json!
{
"branch_id": "branch1",
"menu_id": "bunbo",
"description": "Empty cungx duoc",
"id": "a0a10dc8-1b92-4ee3-84bd-fd9df8446e92",
"is_open": true
}
```
:::
## Get a branch menu item
`GET /branchs/:branchId/menus/:menuId`
:::spoiler Request
`{{domain}}/branchs/branch1/menus/bunbo`
:::
:::spoiler Response
```json!
{
"id": "a0a10dc8-1b92-4ee3-84bd-fd9df8446e92",
"branch_id": "branch1",
"menu_id": "bunbo",
"description": "Empty cungx duoc",
"is_open": true,
"menu_item": {
"id": "bunbo",
"item_name": "Bún cha xả giao",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/0/00/Bun-Bo-Hue-from-Huong-Giang-2011.jpg",
"item_type": "monchinh",
"description": "Mô tả sơ về bún bò",
"price": 30000,
"create_at": "2024-11-01T17:01:45.517Z"
}
}
```
:::
# Order
## Create an order
Tạo một order sẽ dựa theo token role là gì, nếu token có role là Khách hàng thì chỉ được tạo đơn có loại online, ngược lại thì có thể tạo đơn mang đi và tại bàn
**Header** Brearer token
`POST /branchs/:branchId/orders`
:::spoiler Request
```json!
{
"order_type": 2,// online
"order_items":[
{
"menu_id": "bunbo",
"quantity":1
}
],
"note": "Toi muon ve nha",
"delivery_address": "49 Khanh An 12"
}
```
:::
:::spoiler Response
```json
{
"branch": {
"id": "branch1",
"name": "Branch1",
"location": "Pham nhu xuong",
"phone_number": "0796688018",
"create_at": "2024-11-01T17:24:13.867Z"
},
"customer": {
"id": "7ff24ecd-0a08-4669-8340-6c9950e8b0ec",
"avatar": null,
"full_name": "Trần Viết Sơn",
"phone_number": "0912345678",
"address": "Khánh An 12, Liên Chiểu",
"email": "user1@gmail.com",
"role": "CUSTOMER",
"hash_password": "$2b$10$qUXgwZ956dGQ7S8PapUj8OTS2x.QEJEtr0b3zrzcs7BgQbZpiL4U.",
"is_valid": true,
"create_at": "2024-11-01T17:35:16.411Z"
},
"order_type": "online",
"order_status": "pending",
"total_value": 30000,
"customer_id": "7ff24ecd-0a08-4669-8340-6c9950e8b0ec",
"branch_id": "branch1",
"staff_id": null,
"table_number": null,
"payment_id": null,
"id": 1,
"create_at": "2024-11-01T17:36:36.847Z",
"order_items": [
{
"branch_menu": {
"id": "a0a10dc8-1b92-4ee3-84bd-fd9df8446e92",
"branch_id": "branch1",
"menu_id": "bunbo",
"description": "Empty cungx duoc",
"is_open": true,
"menu_item": {
"id": "bunbo",
"item_name": "Bún cha xả giao",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/0/00/Bun-Bo-Hue-from-Huong-Giang-2011.jpg",
"item_type": "monchinh",
"description": "Mô tả sơ về bún bò",
"price": 30000,
"create_at": "2024-11-01T17:01:45.517Z"
}
},
"price": 30000,
"quantity": 1,
"order_id": 1,
"branch_menu_id": "a0a10dc8-1b92-4ee3-84bd-fd9df8446e92",
"id": 1
}
]
}
```
:::
# Report
Doanh thu theo chi nhánh
`/report/revenue/by-branch`
Query:
year: nhập năm
branchId: nhập chi nhánh
:::info
Nếu nhập năm sẽ lọc theo tháng
Nếu nhập branchId sẽ lọc theo branchId, nếu không lấy tất cả
:::
Doanh thu theo Khu vực
`/report/revenue/by-area`
Query:
year: nhập năm
areaId: nhập mã chi nhánh
:::info
Nếu nhập năm sẽ lọc theo tháng
Nếu nhập areaId sẽ lọc theo areaId, nếu không lấy tất cả
:::
# Area
### Get all branch
`GET /area`
:::spoiler Response
```
[
{
"id": 3,
"name": "Nam",
"manager_id": "82131e90-6870-423d-a606-1c6aa33961b7",
"branches": [
{
"id": "branch3",
"name": "CATS - 2/9",
"image_url": "https://statics.vincom.com.vn/xu-huong/nha-hang-da-nang/waterfront-da-nang-restaurant-and-bar.jpg",
"location": "Số 180, đường 2/9, phường Hòa Cường Bắc, quận Hải Châu, Đà Nẵng",
"phone_number": "0977426232",
"table_count": 15,
"area_id": 3,
"create_at": "2024-11-03T16:01:08.784Z",
"delete_at": null
}
],
"manager": {
"id": "82131e90-6870-423d-a606-1c6aa33961b7",
"avatar": "https://i.pinimg.com/236x/eb/57/4e/eb574e15b18bab501f8a2f5cd3879d2a.jpg",
"full_name": "admin",
"phone_number": "0987654321",
"address": null,
"email": "admin@gmail.com",
"role": "ADMIN",
"hash_password": "$2b$10$A8OnVPGLXHlHAxE/JDr.LuyoBf5dK5693jyXtrdkA8PME8x6qOkBO",
"is_valid": true,
"create_at": "2024-11-03T16:52:51.228Z",
"branch_id": null
}
},
{
"id": 2,
"name": "Trung",
"manager_id": "82131e90-6870-423d-a606-1c6aa33961b7",
"branches": [
{
"id": "branch2",
"name": "CATS - Lê Lợi",
"image_url": "https://statics.vincom.com.vn/xu-huong/nha-hang-da-nang/la-ri-ve-gau-che.jpg",
"location": "Số 45, đường Lê Lợi, phường Bến Nghé, quận 1, TP. Hồ Chí Minh",
"phone_number": "0956236231",
"table_count": 10,
"area_id": 2,
"create_at": "2024-11-03T16:01:08.784Z",
"delete_at": null
}
],
"manager": {
"id": "82131e90-6870-423d-a606-1c6aa33961b7",
"avatar": "https://i.pinimg.com/236x/eb/57/4e/eb574e15b18bab501f8a2f5cd3879d2a.jpg",
"full_name": "admin",
"phone_number": "0987654321",
"address": null,
"email": "admin@gmail.com",
"role": "ADMIN",
"hash_password": "$2b$10$A8OnVPGLXHlHAxE/JDr.LuyoBf5dK5693jyXtrdkA8PME8x6qOkBO",
"is_valid": true,
"create_at": "2024-11-03T16:52:51.228Z",
"branch_id": null
}
},
{
"id": 1,
"name": "Bắc",
"manager_id": "82131e90-6870-423d-a606-1c6aa33961b7",
"branches": [
{
"id": "branch1",
"name": "CATS - Nguyễn Chí Thanh",
"image_url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRVafAvrUKYQdvVkn4RwNYRhQTpUi2lo5R6PA&s",
"location": "Số 12, đường Nguyễn Chí Thanh, phường Láng Thượng, quận Đống Đa, Hà Nội",
"phone_number": "0796688018",
"table_count": 20,
"area_id": 1,
"create_at": "2024-11-03T16:01:08.784Z",
"delete_at": null
}
],
"manager": {
"id": "82131e90-6870-423d-a606-1c6aa33961b7",
"avatar": "https://i.pinimg.com/236x/eb/57/4e/eb574e15b18bab501f8a2f5cd3879d2a.jpg",
"full_name": "admin",
"phone_number": "0987654321",
"address": null,
"email": "admin@gmail.com",
"role": "ADMIN",
"hash_password": "$2b$10$A8OnVPGLXHlHAxE/JDr.LuyoBf5dK5693jyXtrdkA8PME8x6qOkBO",
"is_valid": true,
"create_at": "2024-11-03T16:52:51.228Z",
"branch_id": null
}
}
]
```
:::
### Update area manager
`POST {{domain}}/area/:id/manager`
vd: POST {{domain}}/area/1/manager
body:
```
{
"managerId":"c88929d4-d444-4437-8834-82233639bcb8"
}
```
Return object of area
### Get Detail area
`GET area/:id`