Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/services/importReceiptService.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,61 @@ export async function getDetail(receiptId) {
}
}

// ===== Luồng duyệt phiếu nhập (T91-T94) =====

export async function getPendingApprovals({ page = 0, size = 10, status = '' } = {}) {
try {
const { data } = await importReceiptClient.get('/api/import-receipts/pending-approval', {
headers: getAuthorizationHeader(),
params: {
page,
size,
status: status || undefined,
},
})
return data
} catch (error) {
throw normalizeImportReceiptError(error, 'Không thể tải danh sách phiếu chờ duyệt.')
}
}

export async function getApprovalDetail(receiptId) {
try {
const { data } = await importReceiptClient.get(`/api/import-receipts/${receiptId}/approval-detail`, {
headers: getAuthorizationHeader(),
})
return data
} catch (error) {
throw normalizeImportReceiptError(error, 'Không thể tải chi tiết phiếu chờ duyệt.')
}
}

export async function approveImportReceipt(receiptId) {
try {
const { data } = await importReceiptClient.put(`/api/import-receipts/${receiptId}/approve`, null, {
headers: getAuthorizationHeader(),
})
return data
} catch (error) {
throw normalizeImportReceiptError(error, 'Không thể duyệt phiếu nhập.')
}
}

export async function rejectImportReceipt(receiptId, reason) {
try {
const { data } = await importReceiptClient.put(
`/api/import-receipts/${receiptId}/reject`,
{ reason },
{ headers: getAuthorizationHeader() },
)
return data
} catch (error) {
throw normalizeImportReceiptError(error, 'Không thể từ chối phiếu nhập.')
}
Comment on lines +97 to +145

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Thêm timeout cho các API duyệt/từ chối.

Các hàm mới dùng importReceiptClient, nhưng client hiện chưa cấu hình timeout ở Line 6-10. Nếu kết nối treo, UI có thể kẹt ở trạng thái đang tải/đang gửi.

Gợi ý sửa nhanh
 const importReceiptClient = axios.create({
   baseURL: API_BASE_URL,
+  timeout: 15000,
   headers: {
     'Content-Type': 'application/json',
   },
 })

As per path instructions, src/services/**: “Kiểm tra loading/timeout/network error/HTTP error”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/importReceiptService.js` around lines 97 - 145, Thêm cấu hình
timeout cho importReceiptClient để các API duyệt/từ chối không bị treo khi mạng
kẹt. Cập nhật client khởi tạo (nơi tạo importReceiptClient) để đặt timeout mặc
định phù hợp, và đảm bảo các hàm getPendingApprovals, getApprovalDetail,
approveImportReceipt, rejectImportReceipt vẫn dùng client đó. Nếu cần, xử lý lỗi
timeout qua normalizeImportReceiptError để UI nhận được thông báo rõ ràng thay
vì đứng ở trạng thái loading.

Source: Path instructions

}

// ===== Các chức năng xử lý hàng về & kiểm hàng từ dev =====

export async function confirmArrival(receiptId) {
try {
const { data } = await importReceiptClient.put(`/api/import-receipts/${receiptId}/arrival`, null, {
Expand Down
Loading