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

View File

@ -11,10 +11,10 @@ module.exports = (sequelize, DataTypes) => {
factory_name: { type: DataTypes.STRING, unique: true },
permanent_factory_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 },
license_number: { type: DataTypes.STRING, unique: true },
isic_code: { type: DataTypes.STRING, unique: true },
isic_code: { type: DataTypes.STRING},
// Establishment Contact Details
establishment_address: { type: DataTypes.STRING },

View File

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