Skip to content

Commit 97525b2

Browse files
conflict resolve
2 parents f647304 + 315ed1a commit 97525b2

File tree

15 files changed

+203
-678
lines changed

15 files changed

+203
-678
lines changed

api/src/services/contentful.service.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function makeChunks(assetData: any) {
8484
return chunks;
8585
}
8686

87-
const mapLocales = ({ masterLocale, locale, locales }: any) => {
87+
const mapLocales = ({ masterLocale, locale, locales, isNull = false }: any) => {
8888
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
8989
return Object?.keys(locales?.masterLocale)?.[0]
9090
}
@@ -93,7 +93,11 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
9393
return key;
9494
}
9595
}
96-
return locale.toLowerCase();
96+
if (isNull !== true) {
97+
return locale?.toLowerCase?.();
98+
} else {
99+
return null;
100+
}
97101
}
98102

99103
const transformCloudinaryObject = (input: any) => {
@@ -842,7 +846,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
842846
for await (const [localeKey, localeValues] of Object.entries(
843847
values as { [key: string]: any }
844848
)) {
845-
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper });
849+
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper, isNull: true });
846850
const chunks = makeChunks(localeValues);
847851
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
848852
const message = getLogMessage(
@@ -854,15 +858,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
854858
}
855859
const refs: { [key: string]: any } = {};
856860
let chunkIndex = 1;
857-
const filePath = path.join(
858-
entriesSave,
859-
ctName, localeCode
860-
);
861-
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
862-
refs[chunkIndex++] = `${chunkId}-entries.json`;
863-
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
861+
if (localeCode) {
862+
const filePath = path.join(
863+
entriesSave,
864+
ctName,
865+
localeCode
866+
);
867+
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
868+
refs[chunkIndex++] = `${chunkId}-entries.json`;
869+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
870+
}
871+
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
864872
}
865-
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
866873
}
867874
}
868875
} else {
@@ -957,7 +964,8 @@ const createLocale = async (packagePath: string, destination_stack_id: string, p
957964
)
958965
await customLogger(projectId, destination_stack_id, 'info', message);
959966
} else {
960-
if (project?.locales?.[localeData?.code]) {
967+
const newValueLocale = getKeyByValue(project?.locales, localeData?.code);
968+
if (newValueLocale) {
961969
allLocales[title] = newLocale;
962970
const message = getLogMessage(
963971
srcFunc,

api/src/services/migration.service.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,13 @@ const startTestMigration = async (req: Request): Promise<any> => {
255255
break;
256256
}
257257
case CMS.CONTENTFUL: {
258-
await contentfulService?.createLocale(file_path, project?.current_test_stack_id, projectId, project);
259-
await contentfulService?.createRefrence(file_path, project?.current_test_stack_id, projectId);
260-
await contentfulService?.createWebhooks(file_path, project?.current_test_stack_id, projectId);
261-
await contentfulService?.createEnvironment(file_path, project?.current_test_stack_id, projectId);
262-
await contentfulService?.createAssets(file_path, project?.current_test_stack_id, projectId, true);
263-
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
258+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
259+
await contentfulService?.createLocale(cleanLocalPath, project?.current_test_stack_id, projectId, project);
260+
await contentfulService?.createRefrence(cleanLocalPath, project?.current_test_stack_id, projectId);
261+
await contentfulService?.createWebhooks(cleanLocalPath, project?.current_test_stack_id, projectId);
262+
await contentfulService?.createEnvironment(cleanLocalPath, project?.current_test_stack_id, projectId);
263+
await contentfulService?.createAssets(cleanLocalPath, project?.current_test_stack_id, projectId, true);
264+
await contentfulService?.createEntry(cleanLocalPath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
264265
await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId);
265266
break;
266267
}
@@ -332,12 +333,13 @@ const startMigration = async (req: Request): Promise<any> => {
332333
break;
333334
}
334335
case CMS.CONTENTFUL: {
335-
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId, project);
336-
await contentfulService?.createRefrence(file_path, project?.destination_stack_id, projectId);
337-
await contentfulService?.createWebhooks(file_path, project?.destination_stack_id, projectId);
338-
await contentfulService?.createEnvironment(file_path, project?.destination_stack_id, projectId);
339-
await contentfulService?.createAssets(file_path, project?.destination_stack_id, projectId);
340-
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
336+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
337+
await contentfulService?.createLocale(cleanLocalPath, project?.destination_stack_id, projectId, project);
338+
await contentfulService?.createRefrence(cleanLocalPath, project?.destination_stack_id, projectId);
339+
await contentfulService?.createWebhooks(cleanLocalPath, project?.destination_stack_id, projectId);
340+
await contentfulService?.createEnvironment(cleanLocalPath, project?.destination_stack_id, projectId);
341+
await contentfulService?.createAssets(cleanLocalPath, project?.destination_stack_id, projectId);
342+
await contentfulService?.createEntry(cleanLocalPath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
341343
await contentfulService?.createVersionFile(project?.destination_stack_id, projectId);
342344
break;
343345
}
@@ -421,7 +423,6 @@ export const createSourceLocales = async (req: Request) => {
421423

422424
const projectId = req?.params?.projectId;
423425
const locales = req?.body?.locale;
424-
console.info("🚀 ~ createSourceLocales ~ locales:", locales);
425426

426427
try {
427428
// Find the project with the specified projectId

api/src/services/projects.service.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const createProject = async (req: Request) => {
135135
//Add logic to create Project from DB
136136
await ProjectModelLowdb.read();
137137

138-
ProjectModelLowdb.update((data: any) => {
138+
await ProjectModelLowdb.update((data: any) => {
139139
data.projects.push(projectData);
140140
});
141141

@@ -204,7 +204,7 @@ const updateProject = async (req: Request) => {
204204

205205
try {
206206
// Update the project fields
207-
ProjectModelLowdb.update((data: any) => {
207+
await ProjectModelLowdb.update((data: any) => {
208208
data.projects[projectIndex].name = updateData?.name;
209209
data.projects[projectIndex].description = updateData?.description;
210210
if (
@@ -308,7 +308,7 @@ const updateLegacyCMS = async (req: Request) => {
308308
// }
309309

310310
try {
311-
ProjectModelLowdb.update((data: any) => {
311+
await ProjectModelLowdb.update((data: any) => {
312312
data.projects[projectIndex].legacy_cms.cms = legacy_cms;
313313
data.projects[projectIndex].current_step = STEPPER_STEPS.LEGACY_CMS;
314314
data.projects[projectIndex].status = NEW_PROJECT_STATUS[0];
@@ -368,7 +368,7 @@ const updateAffix = async (req: Request) => {
368368
true
369369
)) as number;
370370

371-
ProjectModelLowdb.update((data: any) => {
371+
await ProjectModelLowdb.update((data: any) => {
372372
data.projects[projectIndex].legacy_cms.affix = affix;
373373
data.projects[projectIndex].updated_at = new Date().toISOString();
374374
});
@@ -405,7 +405,7 @@ const affixConfirmation = async (req: Request) => {
405405
true
406406
)) as number;
407407

408-
ProjectModelLowdb.update((data: any) => {
408+
await ProjectModelLowdb.update((data: any) => {
409409
data.projects[projectIndex].legacy_cms.affix_confirmation =
410410
affix_confirmation;
411411
data.projects[projectIndex].updated_at = new Date().toISOString();
@@ -477,7 +477,7 @@ const updateFileFormat = async (req: Request) => {
477477
// }
478478

479479
try {
480-
ProjectModelLowdb.update((data: any) => {
480+
await ProjectModelLowdb.update((data: any) => {
481481
data.projects[projectIndex].legacy_cms.file_format = file_format;
482482
data.projects[projectIndex].legacy_cms.file_path = file_path;
483483
data.projects[projectIndex].legacy_cms.is_fileValid = is_fileValid;
@@ -546,7 +546,7 @@ const fileformatConfirmation = async (req: Request) => {
546546
)) as number;
547547

548548
if (!fileformat_confirmation) {
549-
ProjectModelLowdb.update((data: any) => {
549+
await ProjectModelLowdb.update((data: any) => {
550550
data.projects[projectIndex].legacy_cms.file_format_confirmation =
551551
fileformat_confirmation;
552552
data.projects[projectIndex].updated_at = new Date().toISOString();
@@ -643,7 +643,7 @@ const updateDestinationStack = async (req: Request) => {
643643
if (!res.data.stacks.find((stack: any) => stack.api_key === stack_api_key))
644644
throw new BadRequestError(HTTP_TEXTS.DESTINATION_STACK_NOT_FOUND);
645645

646-
ProjectModelLowdb.update((data: any) => {
646+
await ProjectModelLowdb.update((data: any) => {
647647
data.projects[projectIndex].destination_stack_id = stack_api_key;
648648
data.projects[projectIndex].current_step =
649649
STEPPER_STEPS.DESTINATION_STACK;
@@ -713,11 +713,6 @@ const updateCurrentStep = async (req: Request) => {
713713
const isStepCompleted =
714714
project?.legacy_cms?.cms && project?.legacy_cms?.file_format;
715715

716-
console.info((project.status === NEW_PROJECT_STATUS[0] ||
717-
!isStepCompleted ||
718-
!project?.destination_stack_id ||
719-
project?.content_mapper?.length === 0 ||
720-
!project?.current_test_stack_id) || !project?.migration_execution);
721716

722717
switch (project.current_step) {
723718
case STEPPER_STEPS.LEGACY_CMS: {
@@ -732,7 +727,7 @@ const updateCurrentStep = async (req: Request) => {
732727
throw new BadRequestError(HTTP_TEXTS.CANNOT_PROCEED_LEGACY_CMS);
733728
}
734729

735-
ProjectModelLowdb.update((data: any) => {
730+
await ProjectModelLowdb.update((data: any) => {
736731
data.projects[projectIndex].current_step =
737732
STEPPER_STEPS.DESTINATION_STACK;
738733
data.projects[projectIndex].status =
@@ -760,7 +755,7 @@ const updateCurrentStep = async (req: Request) => {
760755
);
761756
}
762757

763-
ProjectModelLowdb.update((data: any) => {
758+
await ProjectModelLowdb.update((data: any) => {
764759
data.projects[projectIndex].current_step =
765760
STEPPER_STEPS.CONTENT_MAPPING;
766761
data.projects[projectIndex].status = NEW_PROJECT_STATUS[3];
@@ -789,7 +784,7 @@ const updateCurrentStep = async (req: Request) => {
789784
);
790785
}
791786

792-
ProjectModelLowdb.update((data: any) => {
787+
await ProjectModelLowdb.update((data: any) => {
793788
data.projects[projectIndex].current_step =
794789
STEPPER_STEPS.TESTING;
795790
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
@@ -818,7 +813,7 @@ const updateCurrentStep = async (req: Request) => {
818813
);
819814
}
820815

821-
ProjectModelLowdb.update((data: any) => {
816+
await ProjectModelLowdb.update((data: any) => {
822817
data.projects[projectIndex].current_step =
823818
STEPPER_STEPS.MIGRATION;
824819
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
@@ -847,7 +842,7 @@ const updateCurrentStep = async (req: Request) => {
847842
);
848843
}
849844

850-
ProjectModelLowdb.update((data: any) => {
845+
await ProjectModelLowdb.update((data: any) => {
851846
data.projects[projectIndex].current_step =
852847
STEPPER_STEPS.MIGRATION;
853848
data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
@@ -913,7 +908,7 @@ const deleteProject = async (req: Request) => {
913908
await ContentTypesMapperModelLowdb.read();
914909
await FieldMapperModel.read();
915910
if (!isEmpty(content_mapper_id)) {
916-
content_mapper_id.map((item: any) => {
911+
content_mapper_id.map(async (item: any) => {
917912
const contentMapperData = ContentTypesMapperModelLowdb.chain
918913
.get("ContentTypesMappers")
919914
.find({ id: item, projectId: projectId })
@@ -940,17 +935,17 @@ const deleteProject = async (req: Request) => {
940935
.get("ContentTypesMappers")
941936
.findIndex({ id: item, projectId: projectId })
942937
.value();
943-
ContentTypesMapperModelLowdb.update((Cdata: any) => {
938+
await ContentTypesMapperModelLowdb.update((Cdata: any) => {
944939
delete Cdata.ContentTypesMappers[contentMapperID];
945940
});
946941
});
947942
}
948943
//delete Project
949-
ProjectModelLowdb.update((Pdata: any) => {
944+
await ProjectModelLowdb.update((Pdata: any) => {
950945
delete Pdata.projects[projectIndex];
951946
});
952947
} else {
953-
ProjectModelLowdb.update((data: any) => {
948+
await ProjectModelLowdb.update((data: any) => {
954949
data.projects[projectIndex].isDeleted = true;
955950
});
956951
}
@@ -1000,7 +995,7 @@ const revertProject = async (req: Request) => {
1000995
if (!projects) {
1001996
throw new NotFoundError(HTTP_TEXTS.PROJECT_NOT_FOUND);
1002997
} else {
1003-
ProjectModelLowdb.update((data: any) => {
998+
await ProjectModelLowdb.update((data: any) => {
1004999
data.projects[projectIndex].isDeleted = false;
10051000
});
10061001
logger.info(
@@ -1047,7 +1042,7 @@ const updateStackDetails = async (req: Request) => {
10471042
)) as number;
10481043

10491044
try {
1050-
ProjectModelLowdb.update((data: any) => {
1045+
await ProjectModelLowdb.update((data: any) => {
10511046
data.projects[projectIndex].stackDetails = stack_details;
10521047
data.projects[projectIndex].updated_at = new Date().toISOString();
10531048
});
@@ -1109,7 +1104,7 @@ const updateContentMapper = async (req: Request) => {
11091104
)) as number;
11101105

11111106
try {
1112-
ProjectModelLowdb.update((data: any) => {
1107+
await ProjectModelLowdb.update((data: any) => {
11131108
data.projects[projectIndex].mapperKeys = content_mapper;
11141109
data.projects[projectIndex].updated_at = new Date().toISOString();
11151110
});
@@ -1170,7 +1165,7 @@ const updateMigrationExecution = async (req: Request) => {
11701165
try {
11711166

11721167
// Update the project in the `ProjectModelLowdb` database
1173-
ProjectModelLowdb.update((data: any) => {
1168+
await ProjectModelLowdb.update((data: any) => {
11741169
data.projects[projectIndex].migration_execution = true; // Set migration execution to true
11751170
data.projects[projectIndex].updated_at = new Date().toISOString(); // Update the `updated_at` timestamp
11761171
});

0 commit comments

Comments
 (0)