From 644f4b0a940f205e892d2ac1f3295221bc47e609 Mon Sep 17 00:00:00 2001 From: umeshmore45 Date: Mon, 9 Dec 2024 18:19:17 +0530 Subject: [PATCH] refactor code --- api/src/services/runCli.service.ts | 9 ++++----- api/src/services/sitecore.service.ts | 5 ++++- api/src/utils/content-type-creator.utils.ts | 4 +++- cli/packages/contentstack/.gitignore | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/api/src/services/runCli.service.ts b/api/src/services/runCli.service.ts index 5cfa1867..b9490962 100644 --- a/api/src/services/runCli.service.ts +++ b/api/src/services/runCli.service.ts @@ -25,7 +25,7 @@ const addCustomMessageInCliLogs = async (loggerPath: string, level: string = 'in export const runCli = async (rg: string, user_id: string, stack_uid: any, projectId: string, isTest = false, transformePath: string) => { try { - const message: string = isTest ? 'Test Migration Process Completed' : 'Migration Process Completed' + const message: string = isTest ? 'Test Migration Process Completed' : 'Migration Process Completed' const regionPresent = CS_REGIONS?.find((item: string) => item === rg) ?? 'NA'; await AuthenticationModel.read(); const userData = AuthenticationModel.chain @@ -33,7 +33,7 @@ export const runCli = async (rg: string, user_id: string, stack_uid: any, projec .find({ region: regionPresent, user_id }) .value(); if (userData?.authtoken && stack_uid) { - const { BACKUP_DATA, BACKUP_LOG_DIR, BACKUP_FOLDER_NAME, BACKUP_FILE_NAME} = MIGRATION_DATA_CONFIG; + const { BACKUP_DATA, BACKUP_LOG_DIR, BACKUP_FOLDER_NAME, BACKUP_FILE_NAME } = MIGRATION_DATA_CONFIG; const sourcePath = path.join(process.cwd(), MIGRATION_DATA_CONFIG.DATA, stack_uid); const backupPath = path.join(process.cwd(), BACKUP_DATA, `${stack_uid}_${v4().slice(0, 4)}`); await copyDirectory(sourcePath, backupPath); @@ -59,10 +59,9 @@ export const runCli = async (rg: string, user_id: string, stack_uid: any, projec ProjectModelLowdb.write(); } await addCustomMessageInCliLogs(loggerPath, 'info', message); - !isTest && ProjectModelLowdb.update((data:any)=>{ + !isTest && ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].isMigrationCompleted = true; - data.projects[projectIndex].isMigrationStarted = false; - + data.projects[projectIndex].isMigrationStarted = false; }) } }); diff --git a/api/src/services/sitecore.service.ts b/api/src/services/sitecore.service.ts index 5ef4a621..9b95f503 100644 --- a/api/src/services/sitecore.service.ts +++ b/api/src/services/sitecore.service.ts @@ -271,6 +271,7 @@ const createEntry = async ({ packagePath, contentTypes, master_locale = 'en-us', } } } + entryObj.publish_details = []; if (Object.keys?.(entryObj)?.length > 1) { entryLocale[uid] = unflatten(entryObj) ?? {}; const message = getLogMessage( @@ -282,11 +283,13 @@ const createEntry = async ({ packagePath, contentTypes, master_locale = 'en-us', } }); } + const mapperCt: string = (keyMapper[ctType?.contentstackUid] !== "" && keyMapper[ctType?.contentstackUid] !== undefined) ? keyMapper[ctType?.contentstackUid] + : ctType?.contentstackUid; const fileMeta = { "1": `${newLocale}.json` }; const entryPath = path.join( process.cwd(), entrySave, - keyMapper[ctType?.contentstackUid] ?? ctType?.contentstackUid, + mapperCt, newLocale ); await writeFiles(entryPath, fileMeta, entryLocale, newLocale) diff --git a/api/src/utils/content-type-creator.utils.ts b/api/src/utils/content-type-creator.utils.ts index d60363c8..574c43c8 100644 --- a/api/src/utils/content-type-creator.utils.ts +++ b/api/src/utils/content-type-creator.utils.ts @@ -599,7 +599,9 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project schema: [] } let currentCt: any = {}; - if (Object?.keys?.(keyMapper)?.length && keyMapper?.[contentType?.contentstackUid]) { + if (Object?.keys?.(keyMapper)?.length && + keyMapper?.[contentType?.contentstackUid] !== "" && + keyMapper?.[contentType?.contentstackUid] !== undefined) { currentCt = await existingCtMapper({ keyMapper, contentTypeUid: contentType?.contentstackUid, projectId, region, user_id }); } const ctData: any = arrangGroups({ schema: contentType?.fieldMapping, newStack }) diff --git a/cli/packages/contentstack/.gitignore b/cli/packages/contentstack/.gitignore index 9306742c..b871aa85 100644 --- a/cli/packages/contentstack/.gitignore +++ b/cli/packages/contentstack/.gitignore @@ -13,4 +13,5 @@ tsconfig.tsbuildinfo /merge-summary.json !bin /sitecoreMigrationData -/migration-data \ No newline at end of file +/migration-data +/cmsMigrationData \ No newline at end of file