diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index 945408a50..05d625e8e 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -135,7 +135,7 @@ const createProject = async (req: Request) => { //Add logic to create Project from DB await ProjectModelLowdb.read(); - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects.push(projectData); }); @@ -204,7 +204,7 @@ const updateProject = async (req: Request) => { try { // Update the project fields - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].name = updateData?.name; data.projects[projectIndex].description = updateData?.description; if ( @@ -308,7 +308,7 @@ const updateLegacyCMS = async (req: Request) => { // } try { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].legacy_cms.cms = legacy_cms; data.projects[projectIndex].current_step = STEPPER_STEPS.LEGACY_CMS; data.projects[projectIndex].status = NEW_PROJECT_STATUS[0]; @@ -368,7 +368,7 @@ const updateAffix = async (req: Request) => { true )) as number; - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].legacy_cms.affix = affix; data.projects[projectIndex].updated_at = new Date().toISOString(); }); @@ -405,7 +405,7 @@ const affixConfirmation = async (req: Request) => { true )) as number; - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].legacy_cms.affix_confirmation = affix_confirmation; data.projects[projectIndex].updated_at = new Date().toISOString(); @@ -477,7 +477,7 @@ const updateFileFormat = async (req: Request) => { // } try { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].legacy_cms.file_format = file_format; data.projects[projectIndex].legacy_cms.file_path = file_path; data.projects[projectIndex].legacy_cms.is_fileValid = is_fileValid; @@ -546,7 +546,7 @@ const fileformatConfirmation = async (req: Request) => { )) as number; if (!fileformat_confirmation) { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].legacy_cms.file_format_confirmation = fileformat_confirmation; data.projects[projectIndex].updated_at = new Date().toISOString(); @@ -643,7 +643,7 @@ const updateDestinationStack = async (req: Request) => { if (!res.data.stacks.find((stack: any) => stack.api_key === stack_api_key)) throw new BadRequestError(HTTP_TEXTS.DESTINATION_STACK_NOT_FOUND); - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].destination_stack_id = stack_api_key; data.projects[projectIndex].current_step = STEPPER_STEPS.DESTINATION_STACK; @@ -713,11 +713,6 @@ const updateCurrentStep = async (req: Request) => { const isStepCompleted = project?.legacy_cms?.cms && project?.legacy_cms?.file_format; - console.info((project.status === NEW_PROJECT_STATUS[0] || - !isStepCompleted || - !project?.destination_stack_id || - project?.content_mapper?.length === 0 || - !project?.current_test_stack_id) || !project?.migration_execution); switch (project.current_step) { case STEPPER_STEPS.LEGACY_CMS: { @@ -732,7 +727,7 @@ const updateCurrentStep = async (req: Request) => { throw new BadRequestError(HTTP_TEXTS.CANNOT_PROCEED_LEGACY_CMS); } - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].current_step = STEPPER_STEPS.DESTINATION_STACK; data.projects[projectIndex].status = @@ -760,7 +755,7 @@ const updateCurrentStep = async (req: Request) => { ); } - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].current_step = STEPPER_STEPS.CONTENT_MAPPING; data.projects[projectIndex].status = NEW_PROJECT_STATUS[3]; @@ -789,7 +784,7 @@ const updateCurrentStep = async (req: Request) => { ); } - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].current_step = STEPPER_STEPS.TESTING; data.projects[projectIndex].status = NEW_PROJECT_STATUS[4]; @@ -818,7 +813,7 @@ const updateCurrentStep = async (req: Request) => { ); } - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].current_step = STEPPER_STEPS.MIGRATION; data.projects[projectIndex].status = NEW_PROJECT_STATUS[4]; @@ -847,7 +842,7 @@ const updateCurrentStep = async (req: Request) => { ); } - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].current_step = STEPPER_STEPS.MIGRATION; data.projects[projectIndex].status = NEW_PROJECT_STATUS[5]; @@ -913,7 +908,7 @@ const deleteProject = async (req: Request) => { await ContentTypesMapperModelLowdb.read(); await FieldMapperModel.read(); if (!isEmpty(content_mapper_id)) { - content_mapper_id.map((item: any) => { + content_mapper_id.map(async (item: any) => { const contentMapperData = ContentTypesMapperModelLowdb.chain .get("ContentTypesMappers") .find({ id: item, projectId: projectId }) @@ -940,17 +935,17 @@ const deleteProject = async (req: Request) => { .get("ContentTypesMappers") .findIndex({ id: item, projectId: projectId }) .value(); - ContentTypesMapperModelLowdb.update((Cdata: any) => { + await ContentTypesMapperModelLowdb.update((Cdata: any) => { delete Cdata.ContentTypesMappers[contentMapperID]; }); }); } //delete Project - ProjectModelLowdb.update((Pdata: any) => { + await ProjectModelLowdb.update((Pdata: any) => { delete Pdata.projects[projectIndex]; }); } else { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].isDeleted = true; }); } @@ -1000,7 +995,7 @@ const revertProject = async (req: Request) => { if (!projects) { throw new NotFoundError(HTTP_TEXTS.PROJECT_NOT_FOUND); } else { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].isDeleted = false; }); logger.info( @@ -1047,7 +1042,7 @@ const updateStackDetails = async (req: Request) => { )) as number; try { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].stackDetails = stack_details; data.projects[projectIndex].updated_at = new Date().toISOString(); }); @@ -1109,7 +1104,7 @@ const updateContentMapper = async (req: Request) => { )) as number; try { - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].mapperKeys = content_mapper; data.projects[projectIndex].updated_at = new Date().toISOString(); }); @@ -1170,7 +1165,7 @@ const updateMigrationExecution = async (req: Request) => { try { // Update the project in the `ProjectModelLowdb` database - ProjectModelLowdb.update((data: any) => { + await ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].migration_execution = true; // Set migration execution to true data.projects[projectIndex].updated_at = new Date().toISOString(); // Update the `updated_at` timestamp }); diff --git a/ui/src/cmsData/legacyCms.json b/ui/src/cmsData/legacyCms.json index 665a2bda3..7befa1f9f 100644 --- a/ui/src/cmsData/legacyCms.json +++ b/ui/src/cmsData/legacyCms.json @@ -326,7 +326,7 @@ "uid": "cs752bfd62296e4791" }, "title": "Select CMS", - "description": "Select the CMS you are migrating content from.", + "description": "Select the CMS you are migrating content from", "step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.", "lock": false, "active": true, @@ -338,7 +338,7 @@ "uid": "cs6c761d71844ac800" }, "title": "Add Source Affix", - "description": "Add a 2–5 character affix for the source name. Use only letters, no numbers or special characters.", + "description": "Add a 2–5 character affix for the source name. Use only letters, no numbers or special characters", "step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.", "lock": false, "active": false, @@ -350,7 +350,7 @@ "uid": "cs7c935e15de9ea7c8" }, "title": "Select File Format", - "description": "Select the file format compatible with the selected CMS.", + "description": "Select the file format compatible with the selected CMS", "step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.", "lock": false, "active": true, @@ -362,7 +362,7 @@ "uid": "cs0279f1f0ce13e83e" }, "title": "Uploaded File", - "description": "This is the file you have uploaded.", + "description": "This is the file you have uploaded", "step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration.", "lock": false, "active": true, diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index d43675269..8512895b9 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -623,12 +623,22 @@ const Migration = () => { } }); } else { - event.preventDefault(); - const url = `/projects/${projectId}/migration/steps/4`; - navigate(url, { replace: true }); - await updateCurrentStepData(selectedOrganisation.value, projectId); - handleStepChange(3); + const res = await updateCurrentStepData(selectedOrganisation.value, projectId); + if (res?.status === 200) { + setIsLoading(false); + event.preventDefault(); + handleStepChange(3); + const url = `/projects/${projectId}/migration/steps/4`; + navigate(url, { replace: true }); + } else { + setIsLoading(false); + Notification({ + notificationContent: { text: res?.data?.error?.message }, + type: 'error' + }); + } + } }; @@ -722,7 +732,7 @@ const Migration = () => {