Skip to content

Commit

Permalink
feat: revised column mapping for mapping with key and heading exist…
Browse files Browse the repository at this point in the history
…s … (#557)

…in headings
  • Loading branch information
chavda-bhavik authored May 2, 2024
2 parents bbbe90e + 745c45f commit defa858
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ export class ReanameFileHeadings {
const uploadInfo = await this.uploadRepository.findById(_uploadId, 'headings _uploadedFileId customSchema');
const templateColumnItems = JSON.parse(uploadInfo.customSchema) as ITemplateSchemaItem[];

const newHeadings = uploadInfo.headings.reduce((headingsArr, heading) => {
const foundColumnMapping = templateColumnItems.find((mapping) => mapping.columnHeading === heading);
if (foundColumnMapping) headingsArr.push(foundColumnMapping.key);
else headingsArr.push(heading);

return headingsArr;
}, []);
const newHeadings = [...uploadInfo.headings];
templateColumnItems.forEach((mapping) => {
if (!mapping.columnHeading) {
const headingIndex = newHeadings.findIndex((heading) => heading === mapping.key);
if (headingIndex > -1) newHeadings[headingIndex] = '_';
} else {
const columnHeadingIndex = newHeadings.findIndex((heading) => heading === mapping.columnHeading);
const keyHeadingIndex = newHeadings.findIndex((keyHeading) => keyHeading === mapping.key);
if (keyHeadingIndex > -1 && columnHeadingIndex > -1) {
[newHeadings[keyHeadingIndex], newHeadings[columnHeadingIndex]] = [
newHeadings[columnHeadingIndex],
newHeadings[keyHeadingIndex],
];
}
}
});

return resolve({ headings: newHeadings });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ export class BaseReview {

if (totalRecords >= 1) {
const recordObj: Record<string, unknown> = headings.reduce((acc, heading, index) => {
if (heading === '_') return acc;

acc[heading] = typeof record[index] === 'string' ? record[index].trim() : record[index];

return acc;
Expand Down

0 comments on commit defa858

Please sign in to comment.