remove duplicate isic code

This commit is contained in:
unknown 2026-01-29 12:56:31 +05:30
parent 9b5643882c
commit 79d71002fa
3 changed files with 21 additions and 30 deletions

View File

@ -58,7 +58,6 @@ exports.createEstablishment = async (req, res) => {
"factory_name", "factory_name",
"permanent_factory_code", "permanent_factory_code",
"industry_code", "industry_code",
"industry_code_production",
"license_number", "license_number",
"isic_code" "isic_code"
].forEach(key => { ].forEach(key => {
@ -70,7 +69,6 @@ exports.createEstablishment = async (req, res) => {
factory_name, factory_name,
permanent_factory_code, permanent_factory_code,
industry_code, industry_code,
industry_code_production,
industry_code_mismatch_remarks, industry_code_mismatch_remarks,
license_number, license_number,
isic_code, isic_code,
@ -149,7 +147,7 @@ exports.createEstablishment = async (req, res) => {
message: "Missing required field: city/town", message: "Missing required field: city/town",
}); });
} }
if (!industry_code_production) { if (!isic_code) {
return res.status(400).send({ return res.status(400).send({
status: "failed", status: "failed",
message: "Missing required field: Industry Code (Current Production)", message: "Missing required field: Industry Code (Current Production)",
@ -208,7 +206,6 @@ exports.createEstablishment = async (req, res) => {
factory_name: sanitizeStringValue(factory_name), factory_name: sanitizeStringValue(factory_name),
permanent_factory_code: sanitizeStringValue(permanent_factory_code), permanent_factory_code: sanitizeStringValue(permanent_factory_code),
industry_code: sanitizeStringValue(industry_code), industry_code: sanitizeStringValue(industry_code),
industry_code_production: sanitizeStringValue(industry_code_production),
industry_code_mismatch_remarks: sanitizeStringValue(industry_code_mismatch_remarks), industry_code_mismatch_remarks: sanitizeStringValue(industry_code_mismatch_remarks),
license_number: sanitizeStringValue(license_number), license_number: sanitizeStringValue(license_number),
isic_code: sanitizeStringValue(isic_code), isic_code: sanitizeStringValue(isic_code),
@ -593,14 +590,12 @@ exports.getEstablishmentById = async (req, res) => {
// Update establishment // Update establishment
exports.updateEstablishment = async (req, res) => { exports.updateEstablishment = async (req, res) => {
try { try {
// convert empty "" → null BEFORE destructure // convert empty "" → null BEFORE destructure
[ [
"establishment_code", "establishment_code",
"factory_name", "factory_name",
"permanent_factory_code", "permanent_factory_code",
"industry_code", "industry_code",
"industry_code_production",
"license_number", "license_number",
"isic_code" "isic_code"
].forEach(key => { ].forEach(key => {
@ -615,7 +610,7 @@ exports.updateEstablishment = async (req, res) => {
factory_name, factory_name,
establishment_emirate_id, establishment_emirate_id,
establishment_city_town_id, establishment_city_town_id,
industry_code_production, isic_code,
corporate_email, corporate_email,
...estData ...estData
} = req.body; } = req.body;
@ -682,7 +677,7 @@ exports.updateEstablishment = async (req, res) => {
} }
// industry code production // industry code production
if (industry_code_production !== undefined && !industry_code_production) { if ( isic_code!== undefined && !isic_code) {
return res.status(400).json({ return res.status(400).json({
status: "failed", status: "failed",
message: "Missing required field: Industry Code (Current Production)", message: "Missing required field: Industry Code (Current Production)",
@ -722,9 +717,8 @@ exports.updateEstablishment = async (req, res) => {
estData.corporate_email = corporate_email; estData.corporate_email = corporate_email;
// sync industry code & ISIC // sync industry code & ISIC
if (industry_code_production !== undefined) { if (isic_code !== undefined) {
estData.industry_code_production = industry_code_production; estData.isic_code = isic_code;
estData.isic_code = industry_code_production;
} }
estData.updated_by = estData.updated_by || req.user.id; estData.updated_by = estData.updated_by || req.user.id;
@ -1602,7 +1596,7 @@ exports.establishmentBulkUpload = async (req, res) => {
"establishment_code", "establishment_code",
"factory_name", "factory_name",
"establishment_contact_email", "establishment_contact_email",
"industry_code_production", "isic_code",
"permanent_factory_code", "permanent_factory_code",
"industry_code" "industry_code"
] ]
@ -1620,7 +1614,7 @@ exports.establishmentBulkUpload = async (req, res) => {
existingEstSet.add(e.establishment_code); existingEstSet.add(e.establishment_code);
existingFactorySet.add((e.factory_name || "").toLowerCase()); existingFactorySet.add((e.factory_name || "").toLowerCase());
existingEmailSet.add((e.establishment_contact_email || "").toLowerCase()); existingEmailSet.add((e.establishment_contact_email || "").toLowerCase());
if (e.industry_code_production) existingIndustryCodeSet.add(e.industry_code_production); if (e.isic_code) existingIndustryCodeSet.add(e.isic_code);
if (e.permanent_factory_code) existingPermanentFactoryCodeSet.add(e.permanent_factory_code); if (e.permanent_factory_code) existingPermanentFactoryCodeSet.add(e.permanent_factory_code);
if (e.industry_code) existingIndustryCodeBusinessSet.add(e.industry_code); if (e.industry_code) existingIndustryCodeBusinessSet.add(e.industry_code);
} }
@ -1685,18 +1679,18 @@ exports.establishmentBulkUpload = async (req, res) => {
} }
// Check industry_code_production duplicates (if provided) // Check industry_code_production duplicates (if provided)
const industryCodeProd = r.industry_code_current_production ? r.industry_code_current_production.trim() : null; // const industryCodeProd = r.industry_code_current_production ? r.industry_code_current_production.trim() : null;
if (industryCodeProd) { // if (industryCodeProd) {
if (fileIndustryCodeSet.has(industryCodeProd)) { // if (fileIndustryCodeSet.has(industryCodeProd)) {
errors.push({ row: rowNum, error: `Duplicate Industry Code (Current Production) in file: ${industryCodeProd}` }); // errors.push({ row: rowNum, error: `Duplicate Industry Code (Current Production) in file: ${industryCodeProd}` });
continue; // continue;
} // }
if (existingIndustryCodeSet.has(industryCodeProd)) { // if (existingIndustryCodeSet.has(industryCodeProd)) {
errors.push({ row: rowNum, error: `Industry Code (Current Production) already exists in database: ${industryCodeProd}` }); // errors.push({ row: rowNum, error: `Industry Code (Current Production) already exists in database: ${industryCodeProd}` });
continue; // continue;
} // }
fileIndustryCodeSet.add(industryCodeProd); // fileIndustryCodeSet.add(industryCodeProd);
} // }
const permanentFactoryCode = r.permanent_factory_code ? r.permanent_factory_code.trim() : null; const permanentFactoryCode = r.permanent_factory_code ? r.permanent_factory_code.trim() : null;
if (permanentFactoryCode) { if (permanentFactoryCode) {
@ -1886,7 +1880,6 @@ exports.establishmentBulkUpload = async (req, res) => {
establishment_emirate_id: p.emirateId, establishment_emirate_id: p.emirateId,
permanent_factory_code: r.permanent_factory_code || null, permanent_factory_code: r.permanent_factory_code || null,
industry_code: r.industry_code_business_register || null, industry_code: r.industry_code_business_register || null,
industry_code_production: r.industry_code_current_production || null,
isic_code: r.industry_code_current_production || null, isic_code: r.industry_code_current_production || null,
industry_code_mismatch_remarks: r.industry_code_mismatch_remarks || null, industry_code_mismatch_remarks: r.industry_code_mismatch_remarks || null,
description: r.description || null, description: r.description || null,

View File

@ -11,10 +11,10 @@ module.exports = (sequelize, DataTypes) => {
factory_name: { type: DataTypes.STRING, unique: true }, factory_name: { type: DataTypes.STRING, unique: true },
permanent_factory_code: { type: DataTypes.STRING, unique: true, allowNull: true }, permanent_factory_code: { type: DataTypes.STRING, unique: true, allowNull: true },
industry_code: { type: DataTypes.STRING, unique: true, allowNull: true }, industry_code: { type: DataTypes.STRING, unique: true, allowNull: true },
industry_code_production: { type: DataTypes.STRING, unique: true, allowNull: true }, industry_code_production: { type: DataTypes.STRING, allowNull: true },
industry_code_mismatch_remarks: { type: DataTypes.STRING }, industry_code_mismatch_remarks: { type: DataTypes.STRING },
license_number: { type: DataTypes.STRING, unique: true }, license_number: { type: DataTypes.STRING, unique: true },
isic_code: { type: DataTypes.STRING, unique: true }, isic_code: { type: DataTypes.STRING},
// Establishment Contact Details // Establishment Contact Details
establishment_address: { type: DataTypes.STRING }, establishment_address: { type: DataTypes.STRING },

View File

@ -557,7 +557,6 @@ router.get("/testEmail", establishmentController.testEmail);
* factory_name: { type: string } * factory_name: { type: string }
* permanent_factory_code: { type: string } * permanent_factory_code: { type: string }
* industry_code: { type: string } * industry_code: { type: string }
* industry_code_production: { type: string }
* industry_code_mismatch_remarks: { type: string } * industry_code_mismatch_remarks: { type: string }
* license_number: { type: string } * license_number: { type: string }
* isic_code: { type: string } * isic_code: { type: string }
@ -734,7 +733,6 @@ router.get("/establishments/:id",[verifySignature, verifyToken], establishmentCo
* factory_name: { type: string } * factory_name: { type: string }
* permanent_factory_code: { type: string } * permanent_factory_code: { type: string }
* industry_code: { type: string } * industry_code: { type: string }
* industry_code_production: { type: string }
* industry_code_mismatch_remarks: { type: string } * industry_code_mismatch_remarks: { type: string }
* license_number: { type: string } * license_number: { type: string }
* isic_code: { type: string } * isic_code: { type: string }