Skip to content

Commit 6a8596d

Browse files
refactor: add reserved field mappings and improve UID handling in aem.service.ts; update defaultValue to empty string in SearchComponent and TeaserComponent
Bug Fix - CMG-724
1 parent 99fbe8f commit 6a8596d

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

api/src/services/aem.service.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ function getFieldValue(items: any, fieldName: string): any {
144144
return undefined;
145145
}
146146

147+
// Reserved field helper function
148+
const RESERVED_FIELD_MAPPINGS: Record<string, string> = {
149+
'locale': 'cm_locale'
150+
// Add other reserved fields if needed
151+
};
152+
153+
function getActualFieldUid(uid: string, fieldUid: string): string {
154+
if (RESERVED_FIELD_MAPPINGS[uid]) {
155+
return RESERVED_FIELD_MAPPINGS[uid];
156+
}
157+
if (RESERVED_FIELD_MAPPINGS[fieldUid]) {
158+
return RESERVED_FIELD_MAPPINGS[fieldUid];
159+
}
160+
return uid;
161+
}
162+
147163
/**
148164
* Finds and returns the asset object from assetJsonData where assetPath matches the given string.
149165
* @param assetJsonData - The asset JSON data object.
@@ -613,15 +629,16 @@ function processFieldsRecursive(
613629
}
614630

615631
case 'single_line_text': {
616-
const aemFieldName = field?.otherCmsField ? getLastKey(field.otherCmsField, ' > ') : getLastKey(field?.uid);
632+
const aemFieldName = field?.otherCmsField ? getLastKey(field?.otherCmsField, ' > ') : getLastKey(field?.uid);
617633
let value = getFieldValue(items, aemFieldName);
618634
const uid = getLastKey(field?.contentstackFieldUid);
619635

636+
const actualUid = getActualFieldUid(uid, field?.uid);
620637
if (value && typeof value === 'string' && /<[^>]+>/.test(value)) {
621638
value = stripHtmlTags(value);
622639
}
623640

624-
obj[uid] = value !== null && value !== undefined ? String(value) : "";
641+
obj[actualUid] = value !== null && value !== undefined ? String(value) : "";
625642
break;
626643
}
627644

upload-api/migration-aem/libs/contentType/components/SearchComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class SearchComponent extends ContentstackComponent {
4545
uid: key,
4646
displayName: key,
4747
description: "",
48-
defaultValue: null
48+
defaultValue: ""
4949
}).toContentstack(),
5050
object: () => null,
5151
array: () => null

upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class TeaserComponent extends ContentstackComponent {
6565
uid: key,
6666
displayName: key,
6767
description: "",
68-
defaultValue: null
68+
defaultValue: ""
6969
}).toContentstack(),
7070
object: (key, schemaProp) => {
7171
const data = { convertedSchema: schemaProp }

upload-api/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
plan: {
33
dropdown: { optionLimit: 100 }
44
},
5-
cmsType: process.env.CMS_TYPE || 'cmsType',
5+
cmsType: process.env.CMS_TYPE || 'aem',
66
isLocalPath: true,
77
awsData: {
88
awsRegion: 'us-east-2',
@@ -12,5 +12,5 @@ export default {
1212
bucketName: '',
1313
bucketKey: ''
1414
},
15-
localPath: process.env.CONTAINER_PATH || 'your-local-legacy-cms-path',
15+
localPath: process.env.CONTAINER_PATH || '/Users/shobhit.upadhyay/Downloads/templates',
1616
};

0 commit comments

Comments
 (0)