diff --git a/api/src/config/dev.config.ts b/api/src/config/dev.config.ts index 00f69565a..cdd2363dc 100644 --- a/api/src/config/dev.config.ts +++ b/api/src/config/dev.config.ts @@ -12,4 +12,4 @@ export const devConfig = { }, LOG_FILE_PATH: process.platform === "win32" ? ".\\combine.log" : "./combine.log", // Replace with the actual path to your log file -}; \ No newline at end of file +}; diff --git a/api/src/controllers/projects.contentMapper.controller.ts b/api/src/controllers/projects.contentMapper.controller.ts index 6a22299c4..c0623d22d 100644 --- a/api/src/controllers/projects.contentMapper.controller.ts +++ b/api/src/controllers/projects.contentMapper.controller.ts @@ -37,10 +37,13 @@ const resetContentType = async (req: Request, res: Response): Promise => { // res.status(200).json(resp); // }; -const removeContentMapper = async (req: Request, res: Response): Promise => { +const removeContentMapper = async ( + req: Request, + res: Response +): Promise => { const resp = await contentMapperService.removeContentMapper(req); res.status(200).json(resp); -} +}; const getSingleContentTypes = async ( req: Request, @@ -59,5 +62,5 @@ export const contentMapperController = { resetContentType, // removeMapping, getSingleContentTypes, - removeContentMapper + removeContentMapper, }; diff --git a/api/src/models/contentTypesMapper-lowdb.ts b/api/src/models/contentTypesMapper-lowdb.ts index 77c3897a9..2ea7d3128 100644 --- a/api/src/models/contentTypesMapper-lowdb.ts +++ b/api/src/models/contentTypesMapper-lowdb.ts @@ -11,6 +11,7 @@ export interface ContentTypesMapper { contentstackUid: string; status: number; fieldMapping: []; + type : string; } // interface ContentTypesMapper { diff --git a/api/src/server.ts b/api/src/server.ts index 7e9f0cf42..fbaf4cb60 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -103,4 +103,4 @@ try { } catch (e) { logger.error("Error while starting the server!"); logger.error(e); -} \ No newline at end of file +} diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index bd2151a07..0a155cb8a 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -26,7 +26,7 @@ import { ContentTypesMapper } from "../models/contentTypesMapper-lowdb.js"; // Developer service to create dummy contentmapping data const putTestData = async (req: Request) => { const projectId = req.params.projectId; - const contentTypes = req.body.contentTypes; + const contentTypes = req.body.contentTypes; await FieldMapperModel.read(); contentTypes.map((type: any, index: any) => { @@ -35,7 +35,7 @@ const putTestData = async (req: Request) => { const id = field?.id || uuidv4(); fieldIds.push(id); return { id, isDeleted: true, ...field }; - }); + }) ?? []; FieldMapperModel.update((data: any) => { data.field_mapper = [...(data?.field_mapper ?? []), ...fields]; }); @@ -45,7 +45,7 @@ const putTestData = async (req: Request) => { await ContentTypesMapperModelLowdb.read(); const contentIds: string[] = []; const contentType = contentTypes.map((item: any) => { - const id = item?.id || uuidv4(); + const id = item?.id || uuidv4(); contentIds.push(id); return { ...item, id }; }); @@ -532,7 +532,7 @@ const resetAllContentTypesMapping = async (projectId: string) => { try { const contentTypes = cData; for (const contentType of contentTypes) { - if (contentType && !isEmpty(contentType.fieldMapping)) { + if (contentType && !isEmpty(contentType.fieldMapping)) { for (const field of contentType.fieldMapping) { await FieldMapperModel.read(); const fieldData = FieldMapperModel.chain @@ -569,10 +569,8 @@ const resetAllContentTypesMapping = async (projectId: string) => { }); } } - } - return projectDetails; } catch (error: any) { logger.error( @@ -735,13 +733,16 @@ const removeContentMapper = async (req: Request) => { throw new BadRequestError(HTTP_TEXTS.PROJECT_NOT_FOUND); } await ContentTypesMapperModelLowdb.read(); - const cData: ContentTypesMapper[] = projectDetails?.content_mapper.map((cId: string) => { - const contentTypeData: ContentTypesMapper = ContentTypesMapperModelLowdb.chain - .get("ContentTypesMappers") - .find({ id: cId }) - .value(); - return contentTypeData; - }); + const cData: ContentTypesMapper[] = projectDetails?.content_mapper.map( + (cId: string) => { + const contentTypeData: ContentTypesMapper = + ContentTypesMapperModelLowdb.chain + .get("ContentTypesMappers") + .find({ id: cId }) + .value(); + return contentTypeData; + } + ); try { const contentTypes: ContentTypesMapper[] = cData; diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index f6cb13bb8..723a8fba6 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -27,8 +27,8 @@ const getAllProjects = async (req: Request) => { const orgId = req?.params?.orgId; const decodedToken = req.body.token_payload; - const { user_id = "", region = "" } = decodedToken; - + const { user_id = "", region = "" } = decodedToken; + await ProjectModelLowdb.read(); const projects = ProjectModelLowdb.chain .get("projects") @@ -354,7 +354,14 @@ const affixConfirmation = async (req: Request) => { const updateFileFormat = async (req: Request) => { const { orgId, projectId } = req.params; - const { token_payload, file_format,file_path,is_localPath,is_fileValid,awsDetails } = req.body; + const { + token_payload, + file_format, + file_path, + is_localPath, + is_fileValid, + awsDetails, + } = req.body; const srcFunc = "updateFileFormat"; const projectIndex = (await getProjectUtil( projectId, diff --git a/uplaode-api/src/config/index.ts b/uplaode-api/src/config/index.ts index d0722ca5a..95ea0bf7d 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/snehal.pimple/Desktop/package 45.zip' + localPath: '/Users/rohit/Desktop/package 45.zip' }; diff --git a/uplaode-api/src/controllers/sitecore/index.ts b/uplaode-api/src/controllers/sitecore/index.ts index 2ca0823d0..5b8c0549c 100644 --- a/uplaode-api/src/controllers/sitecore/index.ts +++ b/uplaode-api/src/controllers/sitecore/index.ts @@ -17,9 +17,17 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s if (infoMap?.contentTypeUids?.length) { const fieldMapping: any = { contentTypes: [] }; for await (const contentType of infoMap?.contentTypeUids ?? []) { - fieldMapping?.contentTypes?.push( - JSON.parse(readFileSync(`${infoMap?.path}/content_types/${contentType}`, 'utf8')) - ); + const fileContent = readFileSync(`${infoMap?.path}/content_types/${contentType}`, 'utf8'); + const jsonfileContent = JSON.parse(fileContent); + jsonfileContent.type = "content_type"; + fieldMapping?.contentTypes?.push(jsonfileContent); + } + + for await (const contentType of infoMap?.globalFieldUids ?? []) { + const fileContent = readFileSync(`${infoMap?.path}/global_fields/${contentType}`, 'utf8'); + const jsonfileContent = JSON.parse(fileContent); + jsonfileContent.type = "global_field"; + fieldMapping?.contentTypes?.push(jsonfileContent); } const config = { method: 'post',