Product name length incresed

This commit is contained in:
unknown 2025-12-11 12:45:31 +05:30
parent 3c8ace0b7e
commit c5de60c518
8 changed files with 20 additions and 8 deletions

View File

@ -1603,7 +1603,7 @@ exports.establishmentBulkUpload = async (req, res) => {
exports.downloadCompanyProfileSample = async (req, res) => {
try {
const safeBasePath = path.resolve(__dirname, "../uploads");
const safeBasePath = path.resolve(__dirname, "../downloads_csv");
const safeFilePath = path.join(safeBasePath, "company_profile_upload_sample.csv");
// Verify file exists BEFORE sending

View File

@ -156,7 +156,7 @@ exports.deleteProduct = async (req, res) => {
exports.downloadProductSample = async (req, res) => {
try {
const filePath = path.join(__dirname, "../uploads/products_upload_sample.csv");
const filePath = path.join(__dirname, "../downloads_csv/products_upload_sample.csv");
return res.download(filePath, "products_upload_sample.csv");
} catch (error) {
return res.status(500).send({ status: "failed", message: error.message });
@ -226,7 +226,7 @@ const filePath = uploadedPath;
mappedKey = "product_name";
} else if (/unit|measurement|uom|measure/i.test(normalizedKey)) {
mappedKey = "unit";
}
}else if (/desc(ription)?/i.test(normalizedKey)) { mappedKey = "description";}
cleanRow[mappedKey] = row[key]?.trim() || null;
}
@ -240,7 +240,7 @@ const filePath = uploadedPath;
return res.status(400).send({ status: "failed", message: "CSV file is empty or invalid." });
}
const requiredCols = ["hs_code", "product_name", "unit"];
const requiredCols = ["hs_code", "product_name", "unit", "description"];
const headers = Object.keys(results[0]);
const missingCols = requiredCols.filter(col => !headers.includes(col));
@ -265,6 +265,7 @@ const filePath = uploadedPath;
let hsCode = row.hs_code?.replace(/[-\s/]/g, "").trim();
const productName = row.product_name?.replace(/\s+/g, " ").trim();
const unit = row.unit?.trim().toLowerCase();
const description = row.description?.trim().toLowerCase();
if (!hsCode || !productName) {
errors.push({ row: index + 1, error: "Missing required HS Code or Product Name" });
@ -281,6 +282,11 @@ const filePath = uploadedPath;
continue;
}
if (description.length > 1000) {
errors.push({ row: index + 1, error: "HS Description is too long. Maximum allowed length is 1000 characters." });
continue;
}
const normalizedHs = hsCode.replace(/^0+/, "");
if (seenHsCodes.has(normalizedHs)) {
fileDuplicates.add(hsCode);
@ -288,7 +294,7 @@ const filePath = uploadedPath;
}
seenHsCodes.add(normalizedHs);
normalizedRows.push({ hsCode, productName, unit });
normalizedRows.push({ hsCode, productName, unit, description });
}
if (fileDuplicates.size > 0) {
@ -328,6 +334,7 @@ const filePath = uploadedPath;
hs_code: row.hsCode,
product_name: row.productName,
unit_id: unitId,
hs_description: row.description,
created_by: userId,
created_at: new Date(),
});

View File

@ -451,7 +451,7 @@ exports.uploadUnitMasterFromCSV = async (req, res) => {
exports.downloadUnitMasterFile = async (req, res) => {
try {
const safeBasePath = path.resolve(__dirname, "../uploads");
const safeBasePath = path.resolve(__dirname, "../downloads_csv");
const safeFilePath = path.join(safeBasePath, "unit_master_sample.csv");
// Verify file exists BEFORE sending

View File

@ -0,0 +1 @@
HS Code,Product Name,Unit,Description
1 HS Code Product Name Unit Description

View File

@ -6,9 +6,14 @@ module.exports = (sequelize, DataTypes) => {
primaryKey: true,
},
product_name: {
type: DataTypes.STRING,
type: DataTypes.TEXT,
allowNull: false,
unique: true,
validate: {
len: {
args: [0, 1000],
msg: "Product Name is too long. Maximum allowed length is 1000 characters."
}}
},
hs_code: {
type: DataTypes.INTEGER,

View File

@ -1 +0,0 @@
HS Code,Product Name,Unit
1 HS Code Product Name Unit