diff --git a/api/src/constants/index.ts b/api/src/constants/index.ts index 6e02edc21..e3a8c6138 100644 --- a/api/src/constants/index.ts +++ b/api/src/constants/index.ts @@ -139,3 +139,10 @@ export const NEW_PROJECT_STATUS = { 5: 5, //MIGRATION_SUCCESSFUL 6: 6, //MIGRATION_TERMINATED }; + +export const CONTENT_TYPE_STATUS = { + 1: 1, //auto-mapping + 2: 2, //verified + 3: 3, //mapping failed + 4: 4, //auto-dump +} diff --git a/api/src/models/contentTypesMapper-lowdb.ts b/api/src/models/contentTypesMapper-lowdb.ts index 93f22fb23..3846c998e 100644 --- a/api/src/models/contentTypesMapper-lowdb.ts +++ b/api/src/models/contentTypesMapper-lowdb.ts @@ -9,6 +9,7 @@ interface ContentTypesMapper { updateAt: Date; contentstackTitle: string; contentstackUid: string; + status:number; fieldMapping: []; } diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index 3c5fa1ec6..c21772457 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -9,6 +9,8 @@ import { HTTP_CODES, STEPPER_STEPS, NEW_PROJECT_STATUS, + CONTENT_TYPE_STATUS, + VALIDATION_ERRORS } from "../constants/index.js"; import logger from "../utils/logger.js"; import { config } from "../config/index.js"; @@ -96,6 +98,8 @@ const getContentTypes = async (req: Request) => { } const contentMapperId = projectDetails.content_mapper; await ContentTypesMapperModelLowdb.read(); + await FieldMapperModel.read(); + const content_mapper: any = []; contentMapperId.map((data: any) => { const contentMapperData = ContentTypesMapperModelLowdb.chain @@ -104,7 +108,7 @@ const getContentTypes = async (req: Request) => { .value(); content_mapper.push(contentMapperData); }); - + if (!isEmpty(content_mapper)) { if (search) { const filteredResult = content_mapper @@ -275,13 +279,35 @@ const updateContentType = async (req: Request) => { ); throw new BadRequestError(HTTP_TEXTS.INVALID_CONTENT_TYPE); } + + try { await ContentTypesMapperModelLowdb.read(); + + if (fieldMapping) { + fieldMapping.forEach(async(field: any) => { + if (!field.ContentstackFieldType || field.ContentstackFieldType === '' || field.ContentstackFieldType === 'No matches found' || field.contentstackFieldUid === '') { + logger.error( + getLogMessage( + srcFun, + `${VALIDATION_ERRORS.STRING_REQUIRED.replace("$", "ContentstackFieldType or contentstackFieldUid")}` + ) + ); + await ContentTypesMapperModelLowdb.read(); + ContentTypesMapperModelLowdb.update((data: any) => { + data.ContentTypesMappers[updateIndex].status = CONTENT_TYPE_STATUS[3]; + }); + throw new BadRequestError( + `${VALIDATION_ERRORS.STRING_REQUIRED.replace("$", "ContentstackFieldType or contentstackFieldUid")}` + ); + } + }); + } + const updateIndex = ContentTypesMapperModelLowdb.chain .get("ContentTypesMappers") .findIndex({ id: contentTypeId }) .value(); - ContentTypesMapperModelLowdb.update((data: any) => { if (updateIndex >= 0) { data.ContentTypesMappers[updateIndex].otherCmsTitle = @@ -297,6 +323,7 @@ const updateContentType = async (req: Request) => { data.ContentTypesMappers[updateIndex].contentstackUid = contentTypeData?.contentstackUid; } + }); if (updateIndex < 0) { @@ -308,13 +335,14 @@ const updateContentType = async (req: Request) => { ); throw new BadRequestError(HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND); } + if (!isEmpty(fieldMapping)) { await FieldMapperModel.read(); (fieldMapping || []).forEach((field: any) => { const fieldIndex = FieldMapperModel.data.field_mapper.findIndex( (f: any) => f?.id === field?.id ); - if (fieldIndex > -1) { + if (fieldIndex > -1 && field?.ContentstackFieldType !== '') { FieldMapperModel.update((data: any) => { data.field_mapper[fieldIndex] = field; data.field_mapper[fieldIndex].isDeleted = false; @@ -322,13 +350,17 @@ const updateContentType = async (req: Request) => { } }); } + await ContentTypesMapperModelLowdb.read(); + ContentTypesMapperModelLowdb.update((data: any) => { + data.ContentTypesMappers[updateIndex].status = CONTENT_TYPE_STATUS[2]; + }); // fetch updated data to return in response await ContentTypesMapperModelLowdb.read(); const updatedContentType = ContentTypesMapperModelLowdb.chain .get("ContentTypesMappers") .find({ id: contentTypeId }) .value(); - + return { updatedContentType }; } catch (error: any) { logger.error( diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index f3f3def51..17ab17797 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -824,7 +824,6 @@ const ContentMapper = () => { fieldMapping: selectedEntries } }; - const { data, status } = await updateContentType( orgId, projectID, diff --git a/uplaode-api/migration-sitecore/libs/contenttypes.js b/uplaode-api/migration-sitecore/libs/contenttypes.js index 0de0efd3e..da41e8872 100644 --- a/uplaode-api/migration-sitecore/libs/contenttypes.js +++ b/uplaode-api/migration-sitecore/libs/contenttypes.js @@ -483,6 +483,7 @@ const contentTypeMapper = ({ components, standardValues, content_type, basePath, const contentTypeMaker = ({ template, basePath, sitecore_folder }) => { const content_type = { id: template?.id, + status:1, "otherCmsTitle": template?.name, "otherCmsUid": template?.key, "isUpdated": false,