Bỏ qua, đến nội dung

Cấu hình nâng cao

Multer configuration

File upload được xử lý bởi @koa/multer:

Cấu hìnhMô tả
StorageMemory storage (file lưu trong buffer)
File size limitGiới hạn kích thước file upload (cấu hình qua server settings)
File typeChỉ 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 tinMô tả
Số dòngDòng thứ mấy trong file Excel (bắt đầu từ 2, bỏ qua header)
FieldField nào gây lỗi
Lý doType 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 relationXử lý khi import
belongsToTìm bản ghi liên kết theo display field hoặc FK value
hasManyKhông hỗ trợ trực tiếp — cần import riêng
belongsToManyParse 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 onlyTạo mới toàn bộ — lỗi nếu trùng unique field
UpsertTạ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.