feat: trim client and county names in bulk import
This commit is contained in:
@@ -602,9 +602,12 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
|
||||
}
|
||||
|
||||
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) {
|
||||
const clientInDb = await orgModel.findOne({ name: record["Client"] });
|
||||
const clientInDb = await orgModel.findOne({ name: clientName });
|
||||
if (clientInDb) {
|
||||
clientData = {
|
||||
id: clientInDb._id,
|
||||
@@ -614,7 +617,7 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
|
||||
avatar: clientInDb.avatar,
|
||||
};
|
||||
|
||||
clientCache[record["Client"]] = clientData;
|
||||
clientCache[clientName] = clientData;
|
||||
} else {
|
||||
errors.push("Client not found");
|
||||
}
|
||||
@@ -622,9 +625,9 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
|
||||
|
||||
csvData[index].clientData = clientData;
|
||||
|
||||
let countyData = countyCache[record["County"]];
|
||||
let countyData = countyCache[countyName];
|
||||
if (!countyData) {
|
||||
const countyInDb = await orgModel.findOne({ name: record["County"] });
|
||||
const countyInDb = await orgModel.findOne({ name: countyName });
|
||||
if (countyInDb) {
|
||||
countyData = {
|
||||
id: countyInDb._id,
|
||||
@@ -633,7 +636,7 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
|
||||
avatar: countyInDb.avatar,
|
||||
};
|
||||
|
||||
countyCache[record["County"]] = countyData;
|
||||
countyCache[countyName] = countyData;
|
||||
} else {
|
||||
errors.push("County not found");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user