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
79 changes: 52 additions & 27 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/contentstack/migration-v2.git#readme",
"dependencies": {
"@contentstack/cli": "^1.57.0",
"@contentstack/cli": "^1.58.0",
"@contentstack/cli-utilities": "^1.17.1",
"@contentstack/json-rte-serializer": "^3.0.5",
"@contentstack/marketplace-sdk": "^1.5.0",
Expand Down
35 changes: 29 additions & 6 deletions api/src/services/drupal/content-types.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export const generateContentTypeSchemas = async (
(field: any) => field && field?.projectId === projectId
);

// Get content type mappers to lookup contentTypeId by content type UID
const contentTypesMappers = ContentTypesMapperModelLowdb.data?.ContentTypesMappers || [];
const projectContentTypesMappers = contentTypesMappers.filter(
(ct: any) => ct && ct?.projectId === projectId
);

// Log fields with UI changes
const fieldsWithTypeChanges = savedFieldMappings.filter(
(field: any) =>
Expand Down Expand Up @@ -112,11 +118,18 @@ export const generateContentTypeSchemas = async (
fs.readFileSync(uploadApiSchemaFilePath, 'utf8')
);

// Find the content type mapper ID for this content type
const contentTypeMapper = projectContentTypesMappers.find(
(ct: any) => ct?.contentstackUid === uploadApiSchema.uid || ct?.otherCmsUid === uploadApiSchema.uid
);
const contentTypeId = contentTypeMapper?.id;

// Convert upload-api schema to API format WITH saved field mappings from UI
const apiSchema = convertUploadApiSchemaToApiSchema(
uploadApiSchema,
savedFieldMappings,
projectId
projectId,
contentTypeId
);

// Add to combined schema array (NO individual files)
Expand Down Expand Up @@ -188,7 +201,8 @@ export const generateContentTypeSchemas = async (
function convertUploadApiSchemaToApiSchema(
uploadApiSchema: any,
savedFieldMappings: any[] = [],
projectId?: string
projectId?: string,
contentTypeId?: string
): any {
const apiSchema = {
title: uploadApiSchema.title,
Expand All @@ -204,14 +218,23 @@ function convertUploadApiSchemaToApiSchema(
for (const uploadField of uploadApiSchema.schema) {
try {
// Find saved field mapping from database FIRST to get user's field type selection
// IMPORTANT: Filter by contentTypeId to ensure we match the correct field for this content type
const savedMapping = savedFieldMappings.find(
(mapping: any) =>
mapping.contentstackFieldUid === uploadField.contentstackFieldUid ||
mapping.contentstackFieldUid === uploadField.uid ||
mapping.uid === uploadField.contentstackFieldUid ||
mapping.uid === uploadField.uid
// Must match the content type ID if provided
(!contentTypeId || mapping.contentTypeId === contentTypeId) &&
// Then match by field UID
(mapping.contentstackFieldUid === uploadField.contentstackFieldUid ||
mapping.contentstackFieldUid === uploadField.uid ||
mapping.uid === uploadField.contentstackFieldUid ||
mapping.uid === uploadField.uid)
);

// Skip fields that were unselected by the user in the UI (isDeleted: true)
if (savedMapping?.isDeleted === true) {
continue; // Do not include this field in the generated schema
}

// Use UI-selected field type if available, otherwise use upload-api type
const fieldType =
savedMapping?.contentstackFieldType ||
Expand Down
Loading