task-j.0
This commit is contained in:
phaichayon
2026-06-17 14:36:45 +07:00
parent 043edff93a
commit 9f95eaaf98
21 changed files with 1438 additions and 175 deletions

View File

@@ -17,34 +17,57 @@ http://localhost:3000
#### Get All Customers by Branch
```
GET /api/customers/:branch
GET /api/customers
```
**Parameters:**
**Note:** Branch is automatically determined from authentication context.
- `branch` (path parameter, required): Branch identifier
- Examples: `branch-01`, `branch-02`, `head-office`
- `status` (query parameter, optional): Filter by customer status
**Query Parameters:**
- `status` (optional): Filter by customer status
- Values: `active`, `inactive`, `pending`
- `page` (optional): Page number for pagination
- Default: `1`
- `limit` (optional): Number of items per page
- Default: `20`
- Maximum: `100`
- `sortBy` (optional): Field to sort by
- Default: `createdAt`
- Examples: `name`, `createdAt`, `customerStatus`
- `sortOrder` (optional): Sort direction
- Default: `desc`
- Values: `asc`, `desc`
**Examples:**
1. Get all customers from branch-01:
1. Get all customers (default page 1, 20 per page):
```bash
curl http://localhost:3000/api/customers/branch-01
curl http://localhost:3000/api/customers
```
2. Get active customers from branch-02:
2. Get page 2 with 10 items per page:
```bash
curl "http://localhost:3000/api/customers/branch-02?status=active"
curl "http://localhost:3000/api/customers?page=2&limit=10"
```
3. Get pending customers from head-office:
3. Get active customers sorted by name ascending:
```bash
curl "http://localhost:3000/api/customers/head-office?status=pending"
curl "http://localhost:3000/api/customers?status=active&sortBy=name&sortOrder=asc"
```
4. Get recent customers (sorted by createdAt descending):
```bash
curl "http://localhost:3000/api/customers?sortBy=createdAt&sortOrder=desc"
```
5. Combined: filtered, paginated, and sorted:
```bash
curl "http://localhost:3000/api/customers?status=active&page=1&limit=15&sortBy=name&sortOrder=asc"
```
**Response Format:**
@@ -55,22 +78,42 @@ curl "http://localhost:3000/api/customers/head-office?status=pending"
"data": [
{
"id": "cust-001",
"branch": "branch-01",
"branchId": "branch-01",
"name": "สมชาย ใจดี",
"email": "somchai@example.com",
"phone": "081-234-5678",
"company": "บริษัท ไทยธุรกิจ จำกัด",
"address": "123 ถนนสุขุมวิท แขวงคลองตัน เขตคลองเตย กรุงเทพฯ 10110",
"status": "active",
"customerStatus": "active",
"customerType": "corporate",
"crmCustomerCode": "CRM-2024-001",
"erpCustomerCode": null,
"taxId": "0105551234567",
"createdAt": "2024-01-15T09:00:00Z",
"updatedAt": "2024-01-15T09:00:00Z"
}
],
"count": 1,
"message": "Found 1 customer(s) for branch: branch-01"
"pagination": {
"page": 1,
"limit": 20,
"total": 45,
"totalPages": 3,
"hasNext": true,
"hasPrev": false
},
"message": "Found 45 customer(s) (page 1 of 3)"
}
```
**Pagination Response Fields:**
- `page`: Current page number
- `limit`: Number of items per page
- `total`: Total number of items matching the query
- `totalPages`: Total number of pages
- `hasNext`: Whether there is a next page
- `hasPrev`: Whether there is a previous page
#### Get Single Customer by ID
```