docs: dịch 22 file Markdown còn lại sang tiếng Việt có dấu (TEC-2881)
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 18s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 2m15s
Deploy / Build API Image (push) Failing after 28s
Deploy / Build Web Image (push) Failing after 16s
Deploy / Build AI Services Image (push) Failing after 17s
E2E Tests / Playwright E2E (push) Failing after 31s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 1m46s
Security Scanning / Trivy Scan — Web Image (push) Failing after 1m7s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 53s
Security Scanning / Trivy Filesystem Scan (push) Failing after 35s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 0s
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped

Hoàn tất đợt cuối của nhiệm vụ chuyển toàn bộ tài liệu sang tiếng Việt.
Đã dịch 22 file `.md` còn sót (~9.7k dòng) — gồm RUNBOOK, audits,
docs/architecture, docs/load-testing, libs READMEs và các quick references.
Giữ nguyên code blocks, đường dẫn, identifier kỹ thuật, URL và biến môi trường.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-19 03:26:14 +07:00
parent 11f2bf26e6
commit d8b409a9ab
22 changed files with 3697 additions and 3703 deletions

View File

@@ -1,252 +1,252 @@
# API Endpoints Reference
# Tham Khảo API Endpoint
All routes are prefixed with `/api/v1/` except health checks. Authentication uses Bearer JWT tokens.
Tất cả route được prefix với `/api/v1/` ngoại trừ health check. Authentication dùng Bearer JWT token.
> **Interactive docs**: Swagger UI is available at `http://localhost:3001/api/v1/docs` when running the API locally.
> **Tài liệu tương tác**: Swagger UI có sẵn tại `http://localhost:3001/api/v1/docs` khi chạy API local.
## Auth (`/auth`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/auth/register` | Public | Register a new user |
| POST | `/auth/login` | Public | Login with phone and password |
| POST | `/auth/refresh` | Cookie | Refresh access token using httpOnly refresh cookie |
| POST | `/auth/logout` | JWT | Logout and clear auth cookies |
| POST | `/auth/exchange-token` | Public | Exchange OAuth token pair for httpOnly cookies |
| GET | `/auth/profile` | JWT | Get current user profile |
| GET | `/auth/profile/agent` | JWT | Get agent profile for current user |
| PATCH | `/auth/kyc` | Admin | Verify user KYC status |
| POST | `/auth/register` | Public | Đăng ký user mới |
| POST | `/auth/login` | Public | Đăng nhập bằng số điện thoại và mật khẩu |
| POST | `/auth/refresh` | Cookie | Làm mới access token bằng cookie refresh httpOnly |
| POST | `/auth/logout` | JWT | Đăng xuất và xóa cookie auth |
| POST | `/auth/exchange-token` | Public | Trao đổi cặp token OAuth lấy cookie httpOnly |
| GET | `/auth/profile` | JWT | Lấy hồ sơ user hiện tại |
| GET | `/auth/profile/agent` | JWT | Lấy hồ sơ agent của user hiện tại |
| PATCH | `/auth/kyc` | Admin | Verify trạng thái KYC của user |
### OAuth
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/auth/google` | Public | Initiate Google OAuth2 login |
| GET | `/auth/google/callback` | Public | Google OAuth2 callback |
| GET | `/auth/zalo` | Public | Initiate Zalo OAuth2 login |
| GET | `/auth/zalo/callback` | Public | Zalo OAuth2 callback |
| GET | `/auth/google` | Public | Khởi tạo đăng nhập Google OAuth2 |
| GET | `/auth/google/callback` | Public | Callback Google OAuth2 |
| GET | `/auth/zalo` | Public | Khởi tạo đăng nhập Zalo OAuth2 |
| GET | `/auth/zalo/callback` | Public | Callback Zalo OAuth2 |
### User Data (GDPR)
### Dữ Liệu User (GDPR)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| DELETE | `/users/me` | JWT | Request account deletion (30-day grace period) |
| POST | `/users/me/cancel-deletion` | JWT | Cancel pending account deletion |
| GET | `/users/me/export` | JWT | Export user data (GDPR Article 20) |
| DELETE | `/users/:id/force` | Admin | Force-delete user immediately |
| DELETE | `/users/me` | JWT | Yêu cầu xóa tài khoản (thời hạn 30 ngày) |
| POST | `/users/me/cancel-deletion` | JWT | Hủy yêu cầu xóa tài khoản đang chờ |
| GET | `/users/me/export` | JWT | Export dữ liệu user (GDPR Điều 20) |
| DELETE | `/users/:id/force` | Admin | Force-delete user ngay lập tức |
---
## Listings (`/listings`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/listings` | JWT + Quota | Create a new property listing |
| GET | `/listings` | Public | Search and filter property listings |
| GET | `/listings/pending` | Admin | Get listings pending moderation |
| GET | `/listings/:id` | Public | Get listing details by ID |
| PATCH | `/listings/:id/status` | JWT | Update listing status |
| POST | `/listings` | JWT + Quota | Tạo tin đăng bất động sản mới |
| GET | `/listings` | Public | Tìm kiếm và lọc tin đăng |
| GET | `/listings/pending` | Admin | Lấy tin đăng đang chờ duyệt |
| GET | `/listings/:id` | Public | Lấy chi tiết tin đăng theo ID |
| PATCH | `/listings/:id/status` | JWT | Cập nhật trạng thái tin đăng |
| POST | `/listings/:id/media` | JWT | Upload media (multipart file upload) |
| PATCH | `/listings/:id/moderate` | Admin | Moderate a listing |
| PATCH | `/listings/:id/moderate` | Admin | Duyệt một tin đăng |
---
## Search (`/search`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/search` | Public | Full-text and faceted property search |
| GET | `/search/geo` | Public | Geographic radius search |
| POST | `/search/reindex` | Admin | Reindex all properties in Typesense |
| GET | `/search` | Public | Tìm kiếm bất động sản full-text faceted |
| GET | `/search/geo` | Public | Tìm kiếm theo bán kính địa lý |
| POST | `/search/reindex` | Admin | Reindex tất cả bất động sản trong Typesense |
### Saved Searches (`/saved-searches`)
### Saved Search (`/saved-searches`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/saved-searches` | JWT | Save search filters |
| GET | `/saved-searches` | JWT | List saved searches |
| GET | `/saved-searches/:id` | JWT | Get saved search details |
| PATCH | `/saved-searches/:id` | JWT | Update saved search |
| DELETE | `/saved-searches/:id` | JWT | Delete saved search |
| POST | `/saved-searches` | JWT | Lưu bộ lọc tìm kiếm |
| GET | `/saved-searches` | JWT | Lit kê các tìm kiếm đã lưu |
| GET | `/saved-searches/:id` | JWT | Lấy chi tiết tìm kiếm đã lưu |
| PATCH | `/saved-searches/:id` | JWT | Cập nhật tìm kiếm đã lưu |
| DELETE | `/saved-searches/:id` | JWT | Xóa tìm kiếm đã lưu |
---
## Payments (`/payments`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/payments` | JWT | Create a new payment |
| GET | `/payments` | JWT | List transactions for authenticated user |
| GET | `/payments/:id` | JWT | Get payment status by ID |
| POST | `/payments/:id/refund` | Admin | Refund a payment |
| POST | `/payments/callback/:provider` | Public | Payment provider webhook (VNPay, MoMo, ZaloPay) |
| POST | `/payments` | JWT | Tạo thanh toán mới |
| GET | `/payments` | JWT | Lit kê giao dịch của user đã xác thực |
| GET | `/payments/:id` | JWT | Lấy trạng thái thanh toán theo ID |
| POST | `/payments/:id/refund` | Admin | Hoàn tiền một thanh toán |
| POST | `/payments/callback/:provider` | Public | Webhook nhà cung cấp thanh toán (VNPay, MoMo, ZaloPay) |
---
## Subscriptions (`/subscriptions`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/subscriptions/plans` | Public | List all subscription plans |
| GET | `/subscriptions/plans/:tier` | Public | Get subscription plan by tier |
| POST | `/subscriptions` | JWT | Create a new subscription |
| PUT | `/subscriptions/upgrade` | JWT | Upgrade existing subscription |
| DELETE | `/subscriptions` | JWT | Cancel active subscription |
| POST | `/subscriptions/usage` | JWT | Record metered usage |
| GET | `/subscriptions/quota/:metric` | JWT | Check remaining quota for a metric |
| GET | `/subscriptions/billing` | JWT | Get billing history |
| GET | `/subscriptions/plans` | Public | Lit kê tất cả plan subscription |
| GET | `/subscriptions/plans/:tier` | Public | Lấy plan subscription theo tier |
| POST | `/subscriptions` | JWT | Tạo subscription mới |
| PUT | `/subscriptions/upgrade` | JWT | Nâng cấp subscription hiện tại |
| DELETE | `/subscriptions` | JWT | Hủy subscription đang hoạt động |
| POST | `/subscriptions/usage` | JWT | Ghi nhận lượng sử dụng metered |
| GET | `/subscriptions/quota/:metric` | JWT | Kiểm tra quota còn lại theo metric |
| GET | `/subscriptions/billing` | JWT | Lấy lịch sử thanh toán |
---
## Admin (`/admin`)
### User Management
### Quản Lý User
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/admin/users` | Admin | List users with optional filters |
| GET | `/admin/users/:id` | Admin | Get user details by ID |
| PATCH | `/admin/users/status` | Admin | Update user active status |
| POST | `/admin/users/ban` | Admin | Ban or unban a user |
| POST | `/admin/subscriptions/adjust` | Admin | Adjust user subscription plan |
| GET | `/admin/dashboard` | Admin | Get admin dashboard statistics |
| GET | `/admin/revenue` | Admin | Get revenue statistics by date range |
| GET | `/admin/audit-logs` | Admin | Get admin audit logs |
| GET | `/admin/users` | Admin | Liệt kê user với bộ lọc tùy chọn |
| GET | `/admin/users/:id` | Admin | Lấy chi tiết user theo ID |
| PATCH | `/admin/users/status` | Admin | Cập nhật trạng thái active của user |
| POST | `/admin/users/ban` | Admin | Ban hoặc unban user |
| POST | `/admin/subscriptions/adjust` | Admin | Điều chỉnh plan subscription của user |
| GET | `/admin/dashboard` | Admin | Lấy thống kê dashboard admin |
| GET | `/admin/revenue` | Admin | Lấy thống kê doanh thu theo khoảng ngày |
| GET | `/admin/audit-logs` | Admin | Lấy audit log admin |
### Moderation
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/admin/moderation` | Admin | Get listing moderation queue |
| POST | `/admin/moderation/approve` | Admin | Approve a listing |
| POST | `/admin/moderation/reject` | Admin | Reject a listing |
| POST | `/admin/moderation/bulk` | Admin | Bulk approve or reject listings |
| GET | `/admin/kyc` | Admin | Get KYC verification queue |
| POST | `/admin/kyc/approve` | Admin | Approve KYC verification |
| POST | `/admin/kyc/reject` | Admin | Reject KYC verification |
| GET | `/admin/moderation` | Admin | Lấy hàng đợi duyệt tin đăng |
| POST | `/admin/moderation/approve` | Admin | Duyệt một tin đăng |
| POST | `/admin/moderation/reject` | Admin | Từ chối một tin đăng |
| POST | `/admin/moderation/bulk` | Admin | Duyệt hoặc từ chối tin đăng hàng loạt |
| GET | `/admin/kyc` | Admin | Lấy hàng đợi xác minh KYC |
| POST | `/admin/kyc/approve` | Admin | Duyệt xác minh KYC |
| POST | `/admin/kyc/reject` | Admin | Từ chối xác minh KYC |
---
## Notifications (`/notifications`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/notifications/history` | JWT | Get notification history |
| GET | `/notifications/preferences` | JWT | Get notification preferences |
| PUT | `/notifications/preferences` | JWT | Update notification preferences |
| GET | `/notifications/unread` | JWT | Get unread notifications |
| PATCH | `/notifications/:id/read` | JWT | Mark notification as read |
| PATCH | `/notifications/read-all` | JWT | Mark all notifications as read |
| GET | `/notifications/templates` | JWT | Get available notification templates |
| GET | `/notifications/history` | JWT | Lấy lịch sử thông báo |
| GET | `/notifications/preferences` | JWT | Lấy tùy chọn thông báo |
| PUT | `/notifications/preferences` | JWT | Cập nhật tùy chọn thông báo |
| GET | `/notifications/unread` | JWT | Lấy thông báo chưa đọc |
| PATCH | `/notifications/:id/read` | JWT | Đánh dấu thông báo đã đọc |
| PATCH | `/notifications/read-all` | JWT | Đánh dấu tất cả thông báo đã đọc |
| GET | `/notifications/templates` | JWT | Lấy các template thông báo có sẵn |
---
## Analytics (`/analytics`)
All analytics endpoints require JWT and are quota-guarded.
Tất cả endpoint analytics yêu cầu JWT và được giới hạn theo quota.
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/analytics/market-report` | JWT + Quota | Get market report for a city |
| GET | `/analytics/price-trend` | JWT + Quota | Get price trend for a district |
| GET | `/analytics/heatmap` | JWT + Quota | Get price heatmap for a city |
| GET | `/analytics/district-stats` | JWT + Quota | Get statistics by district |
| GET | `/analytics/valuation` | JWT + Quota | Get automated property valuation (AVM) |
| GET | `/analytics/market-report` | JWT + Quota | Lấy báo cáo thị trường cho một thành phố |
| GET | `/analytics/price-trend` | JWT + Quota | Lấy xu hướng giá cho một quận |
| GET | `/analytics/heatmap` | JWT + Quota | Lấy heatmap giá cho một thành phố |
| GET | `/analytics/district-stats` | JWT + Quota | Lấy thống kê theo quận |
| GET | `/analytics/valuation` | JWT + Quota | Lấy định giá bất động sản tự động (AVM) |
---
## Agents (`/agents`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/agents/me/dashboard` | Agent | Get agent dashboard stats |
| POST | `/agents/:agentId/recalculate-score` | Admin | Recalculate agent quality score |
| GET | `/agents/me/dashboard` | Agent | Lấy thống kê dashboard agent |
| POST | `/agents/:agentId/recalculate-score` | Admin | Tính lại điểm chất lượng agent |
---
## Inquiries (`/inquiries`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/inquiries` | JWT | Create inquiry for a listing |
| GET | `/inquiries/listing/:listingId` | JWT | List inquiries by listing |
| GET | `/inquiries/agent/me` | Agent | List inquiries for current agent |
| PATCH | `/inquiries/:id/read` | Agent | Mark inquiry as read |
| POST | `/inquiries` | JWT | Tạo inquiry cho một tin đăng |
| GET | `/inquiries/listing/:listingId` | JWT | Liệt kê inquiry theo tin đăng |
| GET | `/inquiries/agent/me` | Agent | Liệt kê inquiry cho agent hiện tại |
| PATCH | `/inquiries/:id/read` | Agent | Đánh dấu inquiry đã đọc |
---
## Leads (`/leads`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/leads` | Agent | Create lead |
| GET | `/leads` | Agent | List leads for agent |
| GET | `/leads/stats` | Agent | Get lead statistics |
| PATCH | `/leads/:id/status` | Agent | Update lead status |
| DELETE | `/leads/:id` | Agent | Delete lead |
| POST | `/leads` | Agent | Tạo lead |
| GET | `/leads` | Agent | Liệt kê lead cho agent |
| GET | `/leads/stats` | Agent | Lấy thống kê lead |
| PATCH | `/leads/:id/status` | Agent | Cập nhật trạng thái lead |
| DELETE | `/leads/:id` | Agent | Xóa lead |
---
## Reviews (`/reviews`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/reviews` | JWT | Create a review |
| GET | `/reviews` | Public | List reviews by target |
| GET | `/reviews/stats` | Public | Get aggregate rating stats for a target |
| GET | `/reviews/me` | JWT | Get reviews by authenticated user |
| DELETE | `/reviews/:id` | JWT | Delete own review |
| POST | `/reviews` | JWT | Tạo một review |
| GET | `/reviews` | Public | Liệt kê review theo target |
| GET | `/reviews/stats` | Public | Lấy thống kê đánh giá tổng hợp cho một target |
| GET | `/reviews/me` | JWT | Lấy review của user đã xác thực |
| DELETE | `/reviews/:id` | JWT | Xóa review của chính mình |
---
## Health (`/health`)
Health endpoints are **not** prefixed with `/api/v1/`.
Endpoint health **không** prefix với `/api/v1/`.
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/health` | Public | Liveness probe |
| GET | `/health/ready` | Public | Readiness probe (DB + Redis) |
| GET | `/health/db` | Public | Database connectivity check |
| GET | `/health/redis` | Public | Redis connectivity check |
| GET | `/health/db` | Public | Kiểm tra kết nối database |
| GET | `/health/redis` | Public | Kiểm tra kết nối Redis |
---
## MCP (`/mcp`)
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| GET | `/mcp/servers` | JWT | List available MCP servers |
| GET | `/mcp/:serverName/sse` | JWT | Open SSE connection to MCP server |
| POST | `/mcp/:serverName/messages` | JWT | Send message to MCP server session |
| GET | `/mcp/servers` | JWT | Lit kê các MCP server có sẵn |
| GET | `/mcp/:serverName/sse` | JWT | Mở kết nối SSE đến MCP server |
| POST | `/mcp/:serverName/messages` | JWT | Gửi message tới session MCP server |
---
## Metrics
| Method | Path | Auth | Description |
| Method | Path | Auth | Mô tả |
|--------|------|------|-------------|
| POST | `/web-vitals` | Public | Ingest Core Web Vitals metrics |
| POST | `/web-vitals` | Public | Ingest metric Core Web Vitals |
---
## Authentication Summary
## Tóm Tắt Authentication
| Auth Type | Description |
| Loại Auth | Mô tả |
|-----------|-------------|
| **Public** | No authentication required |
| **JWT** | Requires `Authorization: Bearer <token>` header |
| **Admin** | JWT + `ADMIN` role required |
| **Agent** | JWT + `AGENT` role required |
| **Quota** | JWT + subscription quota enforcement |
| **Cookie** | Uses httpOnly refresh token cookie |
| **Public** | Không yêu cầu authentication |
| **JWT** | Yêu cầu header `Authorization: Bearer <token>` |
| **Admin** | JWT + role `ADMIN` |
| **Agent** | JWT + role `AGENT` |
| **Quota** | JWT + giới hạn quota subscription |
| **Cookie** | Dùng cookie refresh token httpOnly |
## Rate Limiting
The following endpoints have stricter rate limits:
Các endpoint sau có rate limit nghiêm ngặt hơn:
- Auth endpoints (register, login, refresh): `10 req/60s`
- OAuth callbacks: `10 req/60s`
- Payment callbacks: `60 req/60s`
- MCP endpoints: `30 req/60s`
- Default: `60 req/60s`
- Endpoint Auth (register, login, refresh): `10 req/60s`
- OAuth callback: `10 req/60s`
- Payment callback: `60 req/60s`
- Endpoint MCP: `30 req/60s`
- Mặc định: `60 req/60s`