diff --git a/api/src/services/contentful.service.ts b/api/src/services/contentful.service.ts index 960366c2a..e1eb70c27 100644 --- a/api/src/services/contentful.service.ts +++ b/api/src/services/contentful.service.ts @@ -757,7 +757,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje content.map((item: any) => { displayField[item?.sys?.id] = { - displayField: item.displayField || "untitled", + displayField: item?.displayField || "untitled", }; } ); @@ -785,7 +785,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje entryData[name][lang] ??= {}; entryData[name][lang][id] ??= {}; locales.push(lang); - const fieldData = currentCT?.fieldMapping?.find((item: any) => key === item?.uid); + const fieldData = currentCT?.fieldMapping?.find?.((item: any) => (key === item?.uid) && (!["text", "url"]?.includes?.(item?.backupFieldType))); const newId = fieldData?.contentstackFieldUid ?? `${key}`?.replace?.(/[^a-zA-Z0-9]+/g, "_"); entryData[name][lang][id][newId] = processField( langValue, diff --git a/upload-api/migration-contentful/libs/contentTypeMapper.js b/upload-api/migration-contentful/libs/contentTypeMapper.js index be69521b7..0edb1cd94 100644 --- a/upload-api/migration-contentful/libs/contentTypeMapper.js +++ b/upload-api/migration-contentful/libs/contentTypeMapper.js @@ -23,11 +23,11 @@ const appDetails = require('../utils/apps/appDetails.json') */ const uidCorrector = (uid, affix) => { let newId = uid; - if (restrictedUid.includes(uid)) { - newId = uid.replace(uid, `${affix}_${uid}`); - newId = newId.replace(/[^a-zA-Z0-9]+/g, '_'); + if (restrictedUid?.includes?.(uid)) { + newId = uid?.replace?.(uid, `${affix}_${uid}`); + newId = newId?.replace?.(/[^a-zA-Z0-9]+/g, '_'); } - return newId.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`); + return newId.replace(/([A-Z])/g, (match) => `_${match?.toLowerCase?.()}`); }; /** @@ -104,10 +104,10 @@ const createFieldObject = (item, contentstackFieldType, backupFieldType, referen otherCmsField: item?.name, otherCmsType: item?.widgetId, contentstackField: item?.name, - contentstackFieldUid: uidCorrector(item?.id), + contentstackFieldUid: uidCorrector(item?.id, item?.prefix), contentstackFieldType: contentstackFieldType, backupFieldType: backupFieldType, - backupFieldUid: uidCorrector(item?.id), + backupFieldUid: uidCorrector(item?.id, item?.prefix), advanced: extractAdvancedFields(item, referenceFields, contentstackFieldType, backupFieldType) }); @@ -368,7 +368,7 @@ const contentTypeMapper = (data) => { otherCmsField: `${item.name} > lat`, otherCmsType: 'Number', contentstackField: `${item.name} > lat`, - contentstackFieldUid: `${uidCorrector(item?.id)}.lat`, + contentstackFieldUid: `${uidCorrector(item?.id, item?.prefix)}.lat`, contentstackFieldType: 'number', backupFieldType: 'number', advanced: { @@ -382,7 +382,7 @@ const contentTypeMapper = (data) => { otherCmsField: `${item.name} > lon`, otherCmsType: 'Number', contentstackField: `${item.name} > lon`, - contentstackFieldUid: `${uidCorrector(item?.id)}.lon`, + contentstackFieldUid: `${uidCorrector(item?.id, item?.prefix)}.lon`, contentstackFieldType: 'number', backupFieldType: 'number', advanced: { diff --git a/upload-api/migration-contentful/libs/createInitialMapper.js b/upload-api/migration-contentful/libs/createInitialMapper.js index ff5ed67f7..400de4da6 100644 --- a/upload-api/migration-contentful/libs/createInitialMapper.js +++ b/upload-api/migration-contentful/libs/createInitialMapper.js @@ -12,7 +12,7 @@ const contentTypeMapper = require('./contentTypeMapper'); /** * Internal module dependencies. */ -const { readFile, writeFile, deleteFolderSync } = require('../utils/helper'); +const { readFile, deleteFolderSync } = require('../utils/helper'); const config = require('../config'); const idArray = require('../utils/restrictedKeyWords'); @@ -109,14 +109,14 @@ const createInitialMapper = async () => { advanced: { mandatory: true } } ]; - const dataArray = data.filter((item) => item.id !== 'title' && item.id !== 'url'); - const contentstackFields = [...uidTitle, ...contentTypeMapper(dataArray)].filter(Boolean); + const contentstackFields = [...uidTitle, ...contentTypeMapper(data)]?.filter?.( + Boolean + ); contentTypeObject.fieldMapping = contentstackFields; initialMapper.push(contentTypeObject); } - // writeFile(path.join(path.resolve(process.cwd(), `${config.data}/${config.contentful.contentful}`), 'schemaTest.json'), JSON.stringify(initialMapper, null, 4)); - deleteFolderSync(path.resolve(process.cwd(), config.data)); + deleteFolderSync(path.resolve(process.cwd(), config?.data)); return { contentTypes: initialMapper }; } catch (error) { console.error('Error saving content type:', error); diff --git a/upload-api/migration-contentful/utils/restrictedKeyWords/index.json b/upload-api/migration-contentful/utils/restrictedKeyWords/index.json index ebee95ed1..ff93e6f3b 100644 --- a/upload-api/migration-contentful/utils/restrictedKeyWords/index.json +++ b/upload-api/migration-contentful/utils/restrictedKeyWords/index.json @@ -41,5 +41,7 @@ "_version", "__v", "locale", - "publish_details" -] + "publish_details", + "title", + "url" +] \ No newline at end of file