Skip to content

Commit 983949b

Browse files
authored
Merge branch 'dev' into feat/add-unit-tests
2 parents 5dca676 + 7488b13 commit 983949b

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

api/src/services/contentMapper.service.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,21 @@ const getExistingContentTypes = async (req: Request) => {
442442
let selectedContentType = null;
443443

444444
if (contentTypeUID) {
445-
const [res] = await safePromise(
445+
const [err, res] = await safePromise(
446446
https({
447447
method: 'GET',
448448
url: `${baseUrl}/${contentTypeUID}`,
449449
headers,
450450
}),
451451
);
452452

453-
selectedContentType = {
454-
title: res?.data?.content_type?.title,
455-
uid: res?.data?.content_type?.uid,
456-
schema: res?.data?.content_type?.schema,
457-
};
453+
if (!err) {
454+
selectedContentType = {
455+
title: res?.data?.content_type?.title,
456+
uid: res?.data?.content_type?.uid,
457+
schema: res?.data?.content_type?.schema,
458+
};
459+
}
458460
}
459461
return {
460462
contentTypes: processedContentTypes,
@@ -549,27 +551,21 @@ const getExistingGlobalFields = async (req: Request) => {
549551
let selectedGlobalField = null;
550552

551553
if (globalFieldUID) {
552-
const [res] = await safePromise(
554+
const [err, res] = await safePromise(
553555
https({
554556
method: 'GET',
555557
url: `${baseUrl}/${globalFieldUID}`,
556558
headers,
557559
}),
558560
);
559561

560-
// if (err) {
561-
// throw new Error(
562-
// `Error fetching selected global field: ${
563-
// err.response?.data || err.message
564-
// }`
565-
// );
566-
// }
567-
568-
selectedGlobalField = {
569-
title: res?.data?.global_field?.title,
570-
uid: res?.data?.global_field?.uid,
571-
schema: res?.data?.global_field?.schema,
572-
};
562+
if (!err) {
563+
selectedGlobalField = {
564+
title: res?.data?.global_field?.title,
565+
uid: res?.data?.global_field?.uid,
566+
schema: res?.data?.global_field?.schema,
567+
};
568+
}
573569
}
574570

575571
return { globalFields: processedGlobalFields, selectedGlobalField };

api/src/utils/content-type-creator.utils.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,24 @@ function buildFieldSchema(item: any, marketPlacePath: string, parentUid = ''): a
160160
}
161161
}
162162

163-
if (blockSchema.length > 0) {
164-
blocks.push({
165-
title: blockRawUid, // Keep original for title
166-
uid: blockUid, // Snake case for uid
167-
schema: removeDuplicateFields(blockSchema)
168-
});
169-
}
163+
blocks.push({
164+
title: blockRawUid, // Keep original for title
165+
uid: blockUid, // Snake case for uid
166+
schema: removeDuplicateFields(blockSchema)
167+
});
170168
}
171169

172-
if (blocks.length > 0) {
173-
return {
174-
data_type: "blocks",
175-
display_name: item?.display_name || rawUid, // Keep original for display
176-
field_metadata: {},
177-
uid: itemUid, // Snake case uid
178-
multiple: true,
179-
mandatory: false,
180-
unique: false,
181-
non_localizable: false,
182-
blocks: removeDuplicateFields(blocks)
183-
};
184-
}
185-
return null;
170+
return {
171+
data_type: "blocks",
172+
display_name: item?.display_name || rawUid, // Keep original for display
173+
field_metadata: {},
174+
uid: itemUid, // Snake case uid
175+
multiple: true,
176+
mandatory: false,
177+
unique: false,
178+
non_localizable: false,
179+
blocks: removeDuplicateFields(blocks)
180+
};
186181
}
187182

188183
if (fieldType === 'group') {
@@ -316,14 +311,25 @@ export function buildSchemaTree(fields: any[], parentUid = '', parentType = '',
316311

317312
if (hasChildren) {
318313
if (fieldType === 'modular_blocks') {
319-
// Get modular block children
314+
// Get modular block children (check both current and backup UIDs)
320315
const mbChildren = fields.filter(f => {
321316
if (!f) return false;
322317
const fUid = f?.contentstackFieldUid || '';
323318
if (!fUid || !fieldUid) return false;
324-
return f?.contentstackFieldType === 'modular_blocks_child' &&
325-
fUid.startsWith(fieldUid + '.') &&
326-
!fUid.substring(fieldUid.length + 1).includes('.');
319+
if (f?.contentstackFieldType !== 'modular_blocks_child') return false;
320+
321+
if (fUid.startsWith(fieldUid + '.') &&
322+
!fUid.substring(fieldUid.length + 1).includes('.')) {
323+
return true;
324+
}
325+
326+
if (oldFieldUid && oldFieldUid !== fieldUid &&
327+
fUid.startsWith(oldFieldUid + '.') &&
328+
!fUid.substring(oldFieldUid.length + 1).includes('.')) {
329+
return true;
330+
}
331+
332+
return false;
327333
});
328334

329335
result.schema = mbChildren.map(child => {

0 commit comments

Comments
 (0)