Duplicate issue on hscode fixed
This commit is contained in:
parent
dea439e4e2
commit
3d33569f09
@ -270,7 +270,7 @@ const filePath = uploadedPath;
|
|||||||
let hsCode = row.hs_code?.replace(/[-\s/]/g, "").trim();
|
let hsCode = row.hs_code?.replace(/[-\s/]/g, "").trim();
|
||||||
const productName = row.product_name?.replace(/\s+/g, " ").trim();
|
const productName = row.product_name?.replace(/\s+/g, " ").trim();
|
||||||
const unit = row.unit?.trim().toLowerCase();
|
const unit = row.unit?.trim().toLowerCase();
|
||||||
const description = row.description?.trim().toLowerCase();
|
const description = row.description?.trim().toLowerCase() || "";
|
||||||
|
|
||||||
if (!hsCode || !productName) {
|
if (!hsCode || !productName) {
|
||||||
errors.push({ row: index + 1, error: "Missing required HS Code or Product Name" });
|
errors.push({ row: index + 1, error: "Missing required HS Code or Product Name" });
|
||||||
@ -356,17 +356,25 @@ const filePath = uploadedPath;
|
|||||||
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
|
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
|
||||||
|
|
||||||
let finalStatus = "success";
|
let finalStatus = "success";
|
||||||
let message = `${inserted.length} products inserted successfully.`;
|
let message = `${inserted.length} units inserted successfully.`;
|
||||||
|
let httpCode = 200;
|
||||||
|
|
||||||
if (errors.length > 0 || duplicates.length > 0) {
|
if (errors.length === 0 && duplicates.length === 0) {
|
||||||
finalStatus = inserted.length > 0 ? "partial_success" : "failed";
|
finalStatus = "success";
|
||||||
message =
|
httpCode = 200;
|
||||||
finalStatus === "partial_success"
|
}
|
||||||
? `${inserted.length} inserted, ${duplicates.length} duplicates skipped, ${errors.length} validation errors.`
|
else if (duplicates.length > 0 || errors.length > 0) {
|
||||||
: `No products imported. ${duplicates.length} duplicates and ${errors.length} validation errors.`;
|
finalStatus = "failed";
|
||||||
|
message = `No units imported. ${duplicates.length} duplicates and ${errors.length} errors found.`;
|
||||||
|
httpCode = 422;
|
||||||
|
}
|
||||||
|
else if (inserted.length === 0) {
|
||||||
|
finalStatus = "failed";
|
||||||
|
message = `No units imported. ${duplicates.length} duplicates and ${errors.length} errors found.`;
|
||||||
|
httpCode = 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(httpCode).send({
|
||||||
status: finalStatus,
|
status: finalStatus,
|
||||||
message,
|
message,
|
||||||
summary: {
|
summary: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user