Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/src/services/contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
}
);
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions upload-api/migration-contentful/libs/contentTypeMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?.()}`);
};

/**
Expand Down Expand Up @@ -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)
});

Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
10 changes: 5 additions & 5 deletions upload-api/migration-contentful/libs/createInitialMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
"_version",
"__v",
"locale",
"publish_details"
]
"publish_details",
"title",
"url"
]
Loading