@@ -126,7 +126,8 @@ const createProject = async (req: Request) => {
126126 isNewStack : false
127127 } ,
128128 mapperKeys : { } ,
129- isMigrationStarted : false
129+ isMigrationStarted : false ,
130+ migration_execution :false ,
130131 } ;
131132
132133 try {
@@ -690,6 +691,8 @@ const updateCurrentStep = async (req: Request) => {
690691 const token_payload = req . body . token_payload ;
691692 const srcFunc = "updateCurrentStep" ;
692693
694+
695+
693696 try {
694697 await ProjectModelLowdb . read ( ) ;
695698 const projectIndex = ( await getProjectUtil (
@@ -709,6 +712,12 @@ const updateCurrentStep = async (req: Request) => {
709712 const isStepCompleted =
710713 project ?. legacy_cms ?. cms && project ?. legacy_cms ?. file_format ;
711714
715+ console . info ( ( project . status === NEW_PROJECT_STATUS [ 0 ] ||
716+ ! isStepCompleted ||
717+ ! project ?. destination_stack_id ||
718+ project ?. content_mapper ?. length === 0 ||
719+ ! project ?. current_test_stack_id ) || ! project ?. migration_execution ) ;
720+
712721 switch ( project . current_step ) {
713722 case STEPPER_STEPS . LEGACY_CMS : {
714723 if ( project . status !== NEW_PROJECT_STATUS [ 0 ] || ! isStepCompleted ) {
@@ -789,12 +798,13 @@ const updateCurrentStep = async (req: Request) => {
789798 }
790799 case STEPPER_STEPS . TESTING : {
791800 if (
792- project . status === NEW_PROJECT_STATUS [ 0 ] ||
801+ ( project . status === NEW_PROJECT_STATUS [ 0 ] ||
793802 ! isStepCompleted ||
794803 ! project ?. destination_stack_id ||
795804 project ?. content_mapper ?. length === 0 ||
796- ! project ?. current_test_stack_id
805+ ! project ?. current_test_stack_id ) || ! project ?. migration_execution
797806 ) {
807+
798808 logger . error (
799809 getLogMessage (
800810 srcFunc ,
@@ -806,44 +816,44 @@ const updateCurrentStep = async (req: Request) => {
806816 HTTP_TEXTS . CANNOT_PROCEED_TEST_MIGRATION
807817 ) ;
808818 }
809-
810- ProjectModelLowdb . update ( ( data : any ) => {
811- data . projects [ projectIndex ] . current_step =
812- STEPPER_STEPS . MIGRATION ;
813- data . projects [ projectIndex ] . status = NEW_PROJECT_STATUS [ 5 ] ;
814- data . projects [ projectIndex ] . updated_at = new Date ( ) . toISOString ( ) ;
815- } ) ;
816- break ;
817- }
818- case STEPPER_STEPS . MIGRATION : {
819- if (
820- project . status === NEW_PROJECT_STATUS [ 0 ] ||
821- ! isStepCompleted ||
822- ! project ?. destination_stack_id ||
823- project ?. content_mapper ?. length === 0 ||
824- ! project ?. current_test_stack_id ||
825- ! project ?. isMigrationStarted
826- ) {
827- logger . error (
828- getLogMessage (
829- srcFunc ,
830- HTTP_TEXTS . CANNOT_PROCEED_MIGRATION ,
831- token_payload
832- )
833- ) ;
834- throw new BadRequestError (
835- HTTP_TEXTS . CANNOT_PROCEED_MIGRATION
836- ) ;
837- }
838-
819+
839820 ProjectModelLowdb . update ( ( data : any ) => {
840821 data . projects [ projectIndex ] . current_step =
841822 STEPPER_STEPS . MIGRATION ;
842- data . projects [ projectIndex ] . status = NEW_PROJECT_STATUS [ 5 ] ;
823+ data . projects [ projectIndex ] . status = NEW_PROJECT_STATUS [ 4 ] ;
843824 data . projects [ projectIndex ] . updated_at = new Date ( ) . toISOString ( ) ;
844825 } ) ;
845826 break ;
846827 }
828+ // case STEPPER_STEPS.MIGRATION: {
829+ // if (
830+ // project.status === NEW_PROJECT_STATUS[0] ||
831+ // !isStepCompleted ||
832+ // !project?.destination_stack_id ||
833+ // project?.content_mapper?.length === 0 ||
834+ // !project?.current_test_stack_id ||
835+ // !project?.isMigrationStarted
836+ // ) {
837+ // logger.error(
838+ // getLogMessage(
839+ // srcFunc,
840+ // HTTP_TEXTS.CANNOT_PROCEED_MIGRATION,
841+ // token_payload
842+ // )
843+ // );
844+ // throw new BadRequestError(
845+ // HTTP_TEXTS.CANNOT_PROCEED_MIGRATION
846+ // );
847+ // }
848+
849+ // ProjectModelLowdb.update((data: any) => {
850+ // data.projects[projectIndex].current_step =
851+ // STEPPER_STEPS.MIGRATION;
852+ // data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
853+ // data.projects[projectIndex].updated_at = new Date().toISOString();
854+ // });
855+ // break;
856+ // }
847857 }
848858 logger . info (
849859 getLogMessage (
@@ -1132,6 +1142,75 @@ const updateContentMapper = async (req: Request) => {
11321142 }
11331143} ;
11341144
1145+ /**
1146+ * Updates the `migration_execution` key for a project in the `ProjectModelLowdb`.
1147+ * @param req - The request object containing parameters and body.
1148+ */
1149+ const updateMigrationExecution = async ( req : Request ) => {
1150+ const { orgId, projectId } = req . params ; // Extract organization and project IDs from the route parameters
1151+ const { token_payload, stack_details } = req . body ; // Extract token payload and stack details from the request body
1152+ const srcFunc = "updateMigrationExecutionKey" ;
1153+
1154+ // Ensure the `ProjectModelLowdb` database is ready to be read
1155+ await ProjectModelLowdb . read ( ) ;
1156+
1157+ // Retrieve the project index using the `getProjectUtil` helper
1158+ const projectIndex = ( await getProjectUtil (
1159+ projectId ,
1160+ {
1161+ id : projectId ,
1162+ org_id : orgId ,
1163+ region : token_payload ?. region ,
1164+ owner : token_payload ?. user_id ,
1165+ } ,
1166+ srcFunc ,
1167+ true
1168+ ) ) as number ;
1169+ try {
1170+
1171+ // Update the project in the `ProjectModelLowdb` database
1172+ ProjectModelLowdb . update ( ( data : any ) => {
1173+ data . projects [ projectIndex ] . migration_execution = true ; // Set migration execution to true
1174+ data . projects [ projectIndex ] . updated_at = new Date ( ) . toISOString ( ) ; // Update the `updated_at` timestamp
1175+ } ) ;
1176+
1177+ // Log success message
1178+ logger . info (
1179+ getLogMessage (
1180+ srcFunc ,
1181+ `migration execution key for project [Id : ${ projectId } ] has been successfully updated.` ,
1182+ token_payload
1183+ )
1184+ ) ;
1185+
1186+ // Return success response
1187+ return {
1188+ status : HTTP_CODES . OK ,
1189+ data : {
1190+ message : HTTP_TEXTS . MIGRATION_EXECUTION_KEY_UPDATED ,
1191+ } ,
1192+ } ;
1193+
1194+ } catch ( error : any ) {
1195+ // Log error message
1196+ logger . error (
1197+ getLogMessage (
1198+ srcFunc ,
1199+ `Error occurred while updating content mapping for project [Id : ${ projectId } ].` ,
1200+ token_payload ,
1201+ error
1202+ )
1203+ ) ;
1204+
1205+ // Throw a custom exception with the error details
1206+ throw new ExceptionFunction (
1207+ error ?. message || HTTP_TEXTS . INTERNAL_ERROR ,
1208+ error ?. statusCode || error ?. status || HTTP_CODES . SERVER_ERROR
1209+ ) ;
1210+ }
1211+ } ;
1212+
1213+
11351214
11361215export const projectService = {
11371216 getAllProjects,
@@ -1148,5 +1227,6 @@ export const projectService = {
11481227 deleteProject,
11491228 revertProject,
11501229 updateStackDetails,
1151- updateContentMapper
1230+ updateContentMapper,
1231+ updateMigrationExecution
11521232} ;
0 commit comments