From 19d66af04410be6c1e56717feb7ce1d8f4299a61 Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 24 Jun 2024 18:02:33 +0530 Subject: [PATCH 1/4] feat:added status key in mapper --- api/src/models/contentTypesMapper-lowdb.ts | 1 + api/src/services/contentMapper.service.ts | 19 +++++++++++++++++-- .../migration-sitecore/libs/contenttypes.js | 1 + uplaode-api/src/config/index.ts | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/src/models/contentTypesMapper-lowdb.ts b/api/src/models/contentTypesMapper-lowdb.ts index 93f22fb2..3846c998 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 3c5fa1ec..29fe02a9 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -96,15 +96,28 @@ 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 .get("ContentTypesMappers") .find({ id: data }) .value(); + + const fieldData = contentMapperData?.fieldMapping.map((fields: any) => { + const fieldMapper = FieldMapperModel.chain + .get("field_mapper") + .find({ id: fields }) + .value(); + return fieldMapper; + }); + + const fieldMapping: any = fieldData; + //console.info("filedMapping ::::::::", fieldMapping) + content_mapper.push(contentMapperData); }); - if (!isEmpty(content_mapper)) { if (search) { const filteredResult = content_mapper @@ -123,6 +136,7 @@ const getContentTypes = async (req: Request) => { a.otherCmsTitle.localeCompare(b.otherCmsTitle) ) ?.slice(skip, Number(skip) + Number(limit)); + //console.info("result::::::::::::", result) } } @@ -281,7 +295,6 @@ const updateContentType = async (req: Request) => { .get("ContentTypesMappers") .findIndex({ id: contentTypeId }) .value(); - ContentTypesMapperModelLowdb.update((data: any) => { if (updateIndex >= 0) { data.ContentTypesMappers[updateIndex].otherCmsTitle = @@ -296,7 +309,9 @@ const updateContentType = async (req: Request) => { contentTypeData?.contentstackTitle; data.ContentTypesMappers[updateIndex].contentstackUid = contentTypeData?.contentstackUid; + data.ContentTypesMappers[updateIndex].status = 2; } + console.info("in update conte type ============>", data.ContentTypesMappers[updateIndex].status,data.ContentTypesMappers[updateIndex] ) }); if (updateIndex < 0) { diff --git a/uplaode-api/migration-sitecore/libs/contenttypes.js b/uplaode-api/migration-sitecore/libs/contenttypes.js index 0de0efd3..da41e887 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, diff --git a/uplaode-api/src/config/index.ts b/uplaode-api/src/config/index.ts index cd32fac5..6bb597f4 100644 --- a/uplaode-api/src/config/index.ts +++ b/uplaode-api/src/config/index.ts @@ -9,5 +9,5 @@ export default { bucketName: 'migartion-test', buketKey: 'project/package 45.zip' }, - localPath: '/Users/umesh.more/Downloads/package 45.zip' + localPath: '/Users/aishwarya.dani/Downloads/package 45.zip' }; From 68aed41480d6c208f8d3b2cb6e7e328db28a3f83 Mon Sep 17 00:00:00 2001 From: AishDani Date: Wed, 26 Jun 2024 19:26:34 +0530 Subject: [PATCH 2/4] added validatoin check for fieldMapping --- api/src/constants/index.ts | 7 +++++ api/src/services/contentMapper.service.ts | 33 ++++++++++++++++++++--- ui/src/components/ContentMapper/index.tsx | 4 ++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/api/src/constants/index.ts b/api/src/constants/index.ts index 6e02edc2..e3a8c613 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/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index 29fe02a9..887cc199 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"; @@ -289,6 +291,23 @@ const updateContentType = async (req: Request) => { ); throw new BadRequestError(HTTP_TEXTS.INVALID_CONTENT_TYPE); } + + if (fieldMapping) { + fieldMapping.forEach((field: any) => { + if (!field.ContentstackFieldType || field.ContentstackFieldType === '' || field.contentstackFieldUid) { + logger.error( + getLogMessage( + srcFun, + `${VALIDATION_ERRORS.STRING_REQUIRED.replace("$", "ContentstackFieldType or contentstackFieldUid")}` + ) + ); + throw new BadRequestError( + `${VALIDATION_ERRORS.STRING_REQUIRED.replace("$", "ContentstackFieldType or contentstackFieldUid")}` + ); + } + }); + } + try { await ContentTypesMapperModelLowdb.read(); const updateIndex = ContentTypesMapperModelLowdb.chain @@ -309,9 +328,8 @@ const updateContentType = async (req: Request) => { contentTypeData?.contentstackTitle; data.ContentTypesMappers[updateIndex].contentstackUid = contentTypeData?.contentstackUid; - data.ContentTypesMappers[updateIndex].status = 2; } - console.info("in update conte type ============>", data.ContentTypesMappers[updateIndex].status,data.ContentTypesMappers[updateIndex] ) + //console.info("in update conte type ============>", data.ContentTypesMappers[updateIndex].status,data.ContentTypesMappers[updateIndex] ) }); if (updateIndex < 0) { @@ -323,13 +341,16 @@ const updateContentType = async (req: Request) => { ); throw new BadRequestError(HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND); } + //console.info("filedMapping :::::::::::", fieldMapping) if (!isEmpty(fieldMapping)) { await FieldMapperModel.read(); + //console.info("in if condition==============>"); (fieldMapping || []).forEach((field: any) => { const fieldIndex = FieldMapperModel.data.field_mapper.findIndex( (f: any) => f?.id === field?.id ); - if (fieldIndex > -1) { + //console.info("############",field?.id, fieldIndex, field) + if (fieldIndex > -1 && field?.ContentstackFieldType !== '') { FieldMapperModel.update((data: any) => { data.field_mapper[fieldIndex] = field; data.field_mapper[fieldIndex].isDeleted = false; @@ -337,13 +358,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(); - + console.info("updated content type :::::::::", updatedContentType) return { updatedContentType }; } catch (error: any) { logger.error( diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index f3f3def5..0fb1e5a6 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -824,13 +824,15 @@ const ContentMapper = () => { fieldMapping: selectedEntries } }; - + console.log("data cs ::::::::::", dataCs) const { data, status } = await updateContentType( orgId, projectID, selectedContentType?.id ?? '', dataCs ); + console.log("in content maaper :::::", data); + if (status == 200) { Notification({ From a4aa10ac780fecab8f409d62f9442f7f5828ea57 Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 27 Jun 2024 15:29:31 +0530 Subject: [PATCH 3/4] refactor:added failed status of mapper --- api/src/services/contentMapper.service.ts | 42 +++++++++++++---------- ui/src/components/ContentMapper/index.tsx | 3 -- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index 887cc199..bbd30d1a 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -292,24 +292,30 @@ const updateContentType = async (req: Request) => { throw new BadRequestError(HTTP_TEXTS.INVALID_CONTENT_TYPE); } - if (fieldMapping) { - fieldMapping.forEach((field: any) => { - if (!field.ContentstackFieldType || field.ContentstackFieldType === '' || field.contentstackFieldUid) { - logger.error( - getLogMessage( - srcFun, - `${VALIDATION_ERRORS.STRING_REQUIRED.replace("$", "ContentstackFieldType or contentstackFieldUid")}` - ) - ); - throw new BadRequestError( - `${VALIDATION_ERRORS.STRING_REQUIRED.replace("$", "ContentstackFieldType or contentstackFieldUid")}` - ); - } - }); - } 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 }) @@ -329,7 +335,7 @@ const updateContentType = async (req: Request) => { data.ContentTypesMappers[updateIndex].contentstackUid = contentTypeData?.contentstackUid; } - //console.info("in update conte type ============>", data.ContentTypesMappers[updateIndex].status,data.ContentTypesMappers[updateIndex] ) + }); if (updateIndex < 0) { @@ -341,7 +347,7 @@ const updateContentType = async (req: Request) => { ); throw new BadRequestError(HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND); } - //console.info("filedMapping :::::::::::", fieldMapping) + if (!isEmpty(fieldMapping)) { await FieldMapperModel.read(); //console.info("in if condition==============>"); @@ -368,7 +374,7 @@ const updateContentType = async (req: Request) => { .get("ContentTypesMappers") .find({ id: contentTypeId }) .value(); - console.info("updated content type :::::::::", updatedContentType) + return { updatedContentType }; } catch (error: any) { logger.error( diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 0fb1e5a6..17ab1779 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -824,15 +824,12 @@ const ContentMapper = () => { fieldMapping: selectedEntries } }; - console.log("data cs ::::::::::", dataCs) const { data, status } = await updateContentType( orgId, projectID, selectedContentType?.id ?? '', dataCs ); - console.log("in content maaper :::::", data); - if (status == 200) { Notification({ From 83447a79e6632fe600481990558fc185dd63d44b Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 27 Jun 2024 15:33:37 +0530 Subject: [PATCH 4/4] refactor:removed logs --- api/src/services/contentMapper.service.ts | 16 +--------------- uplaode-api/src/config/index.ts | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index bbd30d1a..c2177245 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -106,20 +106,9 @@ const getContentTypes = async (req: Request) => { .get("ContentTypesMappers") .find({ id: data }) .value(); - - const fieldData = contentMapperData?.fieldMapping.map((fields: any) => { - const fieldMapper = FieldMapperModel.chain - .get("field_mapper") - .find({ id: fields }) - .value(); - return fieldMapper; - }); - - const fieldMapping: any = fieldData; - //console.info("filedMapping ::::::::", fieldMapping) - content_mapper.push(contentMapperData); }); + if (!isEmpty(content_mapper)) { if (search) { const filteredResult = content_mapper @@ -138,7 +127,6 @@ const getContentTypes = async (req: Request) => { a.otherCmsTitle.localeCompare(b.otherCmsTitle) ) ?.slice(skip, Number(skip) + Number(limit)); - //console.info("result::::::::::::", result) } } @@ -350,12 +338,10 @@ const updateContentType = async (req: Request) => { if (!isEmpty(fieldMapping)) { await FieldMapperModel.read(); - //console.info("in if condition==============>"); (fieldMapping || []).forEach((field: any) => { const fieldIndex = FieldMapperModel.data.field_mapper.findIndex( (f: any) => f?.id === field?.id ); - //console.info("############",field?.id, fieldIndex, field) if (fieldIndex > -1 && field?.ContentstackFieldType !== '') { FieldMapperModel.update((data: any) => { data.field_mapper[fieldIndex] = field; diff --git a/uplaode-api/src/config/index.ts b/uplaode-api/src/config/index.ts index 6bb597f4..cd32fac5 100644 --- a/uplaode-api/src/config/index.ts +++ b/uplaode-api/src/config/index.ts @@ -9,5 +9,5 @@ export default { bucketName: 'migartion-test', buketKey: 'project/package 45.zip' }, - localPath: '/Users/aishwarya.dani/Downloads/package 45.zip' + localPath: '/Users/umesh.more/Downloads/package 45.zip' };