From c5de60c5184ce7b56fd926a68d3239ed8a35304d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Dec 2025 12:45:31 +0530 Subject: [PATCH] Product name length incresed --- app/controllers/establishment.controller.js | 2 +- app/controllers/products.controller.js | 15 +++++++++++---- app/controllers/unitMasterController.js | 2 +- .../company_profile_upload_sample.csv | 0 app/downloads_csv/products_upload_sample.csv | 1 + .../unit_master_sample.csv | 0 app/models/product.model.js | 7 ++++++- app/uploads/products_upload_sample.csv | 1 - 8 files changed, 20 insertions(+), 8 deletions(-) rename app/{uploads => downloads_csv}/company_profile_upload_sample.csv (100%) create mode 100644 app/downloads_csv/products_upload_sample.csv rename app/{uploads => downloads_csv}/unit_master_sample.csv (100%) delete mode 100644 app/uploads/products_upload_sample.csv diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index 7033ba1..1553bd7 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -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 diff --git a/app/controllers/products.controller.js b/app/controllers/products.controller.js index 5f54da5..2cc1505 100644 --- a/app/controllers/products.controller.js +++ b/app/controllers/products.controller.js @@ -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(), }); diff --git a/app/controllers/unitMasterController.js b/app/controllers/unitMasterController.js index 7d779ae..551d187 100644 --- a/app/controllers/unitMasterController.js +++ b/app/controllers/unitMasterController.js @@ -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 diff --git a/app/uploads/company_profile_upload_sample.csv b/app/downloads_csv/company_profile_upload_sample.csv similarity index 100% rename from app/uploads/company_profile_upload_sample.csv rename to app/downloads_csv/company_profile_upload_sample.csv diff --git a/app/downloads_csv/products_upload_sample.csv b/app/downloads_csv/products_upload_sample.csv new file mode 100644 index 0000000..9ad3957 --- /dev/null +++ b/app/downloads_csv/products_upload_sample.csv @@ -0,0 +1 @@ +HS Code,Product Name,Unit,Description diff --git a/app/uploads/unit_master_sample.csv b/app/downloads_csv/unit_master_sample.csv similarity index 100% rename from app/uploads/unit_master_sample.csv rename to app/downloads_csv/unit_master_sample.csv diff --git a/app/models/product.model.js b/app/models/product.model.js index 39d6c7d..9a0d619 100644 --- a/app/models/product.model.js +++ b/app/models/product.model.js @@ -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, diff --git a/app/uploads/products_upload_sample.csv b/app/uploads/products_upload_sample.csv deleted file mode 100644 index ca5de20..0000000 --- a/app/uploads/products_upload_sample.csv +++ /dev/null @@ -1 +0,0 @@ -HS Code,Product Name,Unit