Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions api/src/models/contentTypesMapper-lowdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ContentTypesMapper {
updateAt: Date;
contentstackTitle: string;
contentstackUid: string;
status:number;
fieldMapping: [];
}

Expand Down
40 changes: 36 additions & 4 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -104,7 +108,7 @@ const getContentTypes = async (req: Request) => {
.value();
content_mapper.push(contentMapperData);
});

if (!isEmpty(content_mapper)) {
if (search) {
const filteredResult = content_mapper
Expand Down Expand Up @@ -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 =
Expand All @@ -297,6 +323,7 @@ const updateContentType = async (req: Request) => {
data.ContentTypesMappers[updateIndex].contentstackUid =
contentTypeData?.contentstackUid;
}

});

if (updateIndex < 0) {
Expand All @@ -308,27 +335,32 @@ 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;
});
}
});
}
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(
Expand Down
1 change: 0 additions & 1 deletion ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@ const ContentMapper = () => {
fieldMapping: selectedEntries
}
};

const { data, status } = await updateContentType(
orgId,
projectID,
Expand Down
1 change: 1 addition & 0 deletions uplaode-api/migration-sitecore/libs/contenttypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down