Giao diện
Cấu hình nâng cao
Multer configuration
File upload được xử lý bởi @koa/multer:
| Cấu hình | Mô tả |
|---|---|
| Storage | Memory storage (file lưu trong buffer) |
| File size limit | Giới hạn kích thước file upload (cấu hình qua server settings) |
| File type | Chỉ chấp nhận .xlsx |
Error handler registration
Plugin đăng ký custom error handler để trả response có cấu trúc khi import lỗi:
ImportValidationError→ HTTP 400 với danh sách dòng lỗi chi tiết.ImportError→ HTTP 500 với mô tả lỗi kỹ thuật.
Client parse response lỗi và hiển thị trong modal import:
| Thông tin | Mô tả |
|---|---|
| Số dòng | Dòng thứ mấy trong file Excel (bắt đầu từ 2, bỏ qua header) |
| Field | Field nào gây lỗi |
| Lý do | Type mismatch, required violation, unique constraint, v.v. |
Association resolution
Khi import dữ liệu có relation field, hệ thống tự resolve association:
| Loại relation | Xử lý khi import |
|---|---|
belongsTo | Tìm bản ghi liên kết theo display field hoặc FK value |
hasMany | Không hỗ trợ trực tiếp — cần import riêng |
belongsToMany | Parse danh sách giá trị phân cách bởi dấu phẩy |
Lưu ý
Khi import belongsTo field, hệ thống tìm bản ghi liên kết theo title field (display field). Nếu không tìm thấy, dòng đó sẽ lỗi với ImportValidationError.
Chế độ insert / upsert
| Chế độ | Mô tả |
|---|---|
| Insert only | Tạo mới toàn bộ — lỗi nếu trùng unique field |
| Upsert | Tạo mới hoặc cập nhật nếu bản ghi đã tồn tại (match theo unique field) |
Import lớn
Với file Excel nhiều dòng (hàng ngàn), import đồng bộ có thể chậm hoặc timeout. Cân nhắc sử dụng plugin-action-import-pro cho async mode.