empty value issue fixed in company profile bulk upload
This commit is contained in:
parent
423bbbb61e
commit
1410626697
@ -1197,22 +1197,27 @@ exports.establishmentBulkUpload = async (req, res) => {
|
|||||||
"establishment_code",
|
"establishment_code",
|
||||||
"factory_name",
|
"factory_name",
|
||||||
"establishment_contact_email",
|
"establishment_contact_email",
|
||||||
"industry_code_production"
|
"industry_code_production",
|
||||||
|
"permanent_factory_code",
|
||||||
|
"industry_code"
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
const existingEstSet = new Set(existing.map(e => e.establishment_code));
|
const existingEstSet = new Set(existing.map(e => e.establishment_code));
|
||||||
const existingFactorySet = new Set(existing.map(e => e.factory_name.toLowerCase()));
|
const existingFactorySet = new Set(existing.map(e => e.factory_name.toLowerCase()));
|
||||||
const existingEmailSet = new Set(existing.map(e => e.establishment_contact_email.toLowerCase()));
|
const existingEmailSet = new Set(existing.map(e => e.establishment_contact_email.toLowerCase()));
|
||||||
const existingIndustryCodeSet = new Set(
|
const existingIndustryCodeSet = new Set( existing.map(e => e.industry_code_production).filter(Boolean));
|
||||||
existing.map(e => e.industry_code_production).filter(Boolean)
|
const existingPermanentFactoryCodeSet = new Set( existing.map(e => e.permanent_factory_code).filter(Boolean));
|
||||||
);
|
const existingIndustryCodeBusinessSet = new Set( existing.map(e => e.industry_code).filter(Boolean));
|
||||||
|
|
||||||
// FILE duplicate trackers
|
// FILE duplicate trackers
|
||||||
const fileEstSet = new Set();
|
const fileEstSet = new Set();
|
||||||
const fileFactorySet = new Set();
|
const fileFactorySet = new Set();
|
||||||
const fileEmailSet = new Set();
|
const fileEmailSet = new Set();
|
||||||
const fileIndustryCodeSet = new Set();
|
const fileIndustryCodeSet = new Set();
|
||||||
|
const filePermanentFactoryCodeSet = new Set();
|
||||||
|
const fileIndustryCodeBusinessSet = new Set();
|
||||||
|
|
||||||
|
|
||||||
const errors = [];
|
const errors = [];
|
||||||
const prepared = [];
|
const prepared = [];
|
||||||
@ -1277,6 +1282,32 @@ exports.establishmentBulkUpload = async (req, res) => {
|
|||||||
}
|
}
|
||||||
fileIndustryCodeSet.add(industryCodeProd);
|
fileIndustryCodeSet.add(industryCodeProd);
|
||||||
}
|
}
|
||||||
|
const permanentFactoryCode = r.permanent_factory_code?.trim();
|
||||||
|
if (permanentFactoryCode) {
|
||||||
|
if (filePermanentFactoryCodeSet.has(permanentFactoryCode)) {
|
||||||
|
errors.push({ row: rowNum, error: `Duplicate Permanent Factory Code in file: ${permanentFactoryCode}` });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (existingPermanentFactoryCodeSet.has(permanentFactoryCode)) {
|
||||||
|
errors.push({ row: rowNum, error: `Permanent Factory Code already exists in database: ${permanentFactoryCode}` });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
filePermanentFactoryCodeSet.add(permanentFactoryCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check industry_code_business_register duplicates (if provided)
|
||||||
|
const industryCodeBusiness = r.industry_code_business_register?.trim();
|
||||||
|
if (industryCodeBusiness) {
|
||||||
|
if (fileIndustryCodeBusinessSet.has(industryCodeBusiness)) {
|
||||||
|
errors.push({ row: rowNum, error: `Duplicate Industry Code (Business Register) in file: ${industryCodeBusiness}` });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (existingIndustryCodeBusinessSet.has(industryCodeBusiness)) {
|
||||||
|
errors.push({ row: rowNum, error: `Industry Code (Business Register) already exists in database: ${industryCodeBusiness}` });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fileIndustryCodeBusinessSet.add(industryCodeBusiness);
|
||||||
|
}
|
||||||
|
|
||||||
fileEstSet.add(estKey);
|
fileEstSet.add(estKey);
|
||||||
fileFactorySet.add(factoryKey);
|
fileFactorySet.add(factoryKey);
|
||||||
@ -1379,21 +1410,20 @@ exports.establishmentBulkUpload = async (req, res) => {
|
|||||||
factory_name: p.factory,
|
factory_name: p.factory,
|
||||||
establishment_contact_email: p.email,
|
establishment_contact_email: p.email,
|
||||||
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,
|
industry_code: r.industry_code_business_register || null,
|
||||||
industry_code: r.industry_code_business_register,
|
industry_code_production: r.industry_code_current_production || null,
|
||||||
industry_code_production: r.industry_code_current_production,
|
industry_code_mismatch_remarks: r.industry_code_mismatch_remarks || null,
|
||||||
industry_code_mismatch_remarks: r.industry_code_mismatch_remarks,
|
description: r.description || null,
|
||||||
description: r.description,
|
establishment_address: r.establishment_address || null,
|
||||||
establishment_address: r.establishment_address,
|
establishment_city_town_id: r.city_town_id || null,
|
||||||
establishment_city_town_id: r.city_town_id,
|
establishment_postal_code: r.postal_code || null,
|
||||||
establishment_postal_code: r.postal_code,
|
establishment_po_box: r.po_box || null,
|
||||||
establishment_po_box: r.po_box,
|
establishment_makani_number: r.makani_number || null,
|
||||||
establishment_makani_number: r.makani_number,
|
establishment_contact_person_name: r.contact_person_name || null,
|
||||||
establishment_contact_person_name: r.contact_person_name,
|
establishment_contact_person_designation: r.contact_person_designation || null,
|
||||||
establishment_contact_person_designation: r.contact_person_designation,
|
establishment_mobile_number: r.mobile_number || null,
|
||||||
establishment_mobile_number: r.mobile_number,
|
establishment_website: r.website || null,
|
||||||
establishment_website: r.website,
|
|
||||||
|
|
||||||
emirati_male: Number(r.number_of_emirati_male || 0),
|
emirati_male: Number(r.number_of_emirati_male || 0),
|
||||||
emirati_female: Number(r.number_of_emirati_female || 0),
|
emirati_female: Number(r.number_of_emirati_female || 0),
|
||||||
@ -1432,7 +1462,7 @@ exports.establishmentBulkUpload = async (req, res) => {
|
|||||||
support_email: process.env.SUPPORT_EMAIL,
|
support_email: process.env.SUPPORT_EMAIL,
|
||||||
support_phone: process.env.SUPPORT_PHONE
|
support_phone: process.env.SUPPORT_PHONE
|
||||||
};
|
};
|
||||||
await sendEmailService(p.email, "establishment_user_creation_to_user", placeHolderData);
|
// await sendEmailService(p.email, "establishment_user_creation_to_user", placeHolderData);
|
||||||
|
|
||||||
await EstablishmentProduct.bulkCreate(
|
await EstablishmentProduct.bulkCreate(
|
||||||
p.productIds.map(pid => ({
|
p.productIds.map(pid => ({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user