feat: trim client and county names in bulk import

This commit is contained in:
2026-01-02 17:07:36 +05:30
parent 79a65547e1
commit 202f61b2e0

View File

@@ -602,9 +602,12 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
} }
if (record["County"] && record["Client"]) { if (record["County"] && record["Client"]) {
let clientData = clientCache[record["Client"]]; const clientName = record["Client"].trim();
const countyName = record["County"].trim();
let clientData = clientCache[clientName];
if (!clientData) { if (!clientData) {
const clientInDb = await orgModel.findOne({ name: record["Client"] }); const clientInDb = await orgModel.findOne({ name: clientName });
if (clientInDb) { if (clientInDb) {
clientData = { clientData = {
id: clientInDb._id, id: clientInDb._id,
@@ -614,7 +617,7 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
avatar: clientInDb.avatar, avatar: clientInDb.avatar,
}; };
clientCache[record["Client"]] = clientData; clientCache[clientName] = clientData;
} else { } else {
errors.push("Client not found"); errors.push("Client not found");
} }
@@ -622,9 +625,9 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
csvData[index].clientData = clientData; csvData[index].clientData = clientData;
let countyData = countyCache[record["County"]]; let countyData = countyCache[countyName];
if (!countyData) { if (!countyData) {
const countyInDb = await orgModel.findOne({ name: record["County"] }); const countyInDb = await orgModel.findOne({ name: countyName });
if (countyInDb) { if (countyInDb) {
countyData = { countyData = {
id: countyInDb._id, id: countyInDb._id,
@@ -633,7 +636,7 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
avatar: countyInDb.avatar, avatar: countyInDb.avatar,
}; };
countyCache[record["County"]] = countyData; countyCache[countyName] = countyData;
} else { } else {
errors.push("County not found"); errors.push("County not found");
} }