From e61d772be470aff42599f31b892d5a0f93f648f8 Mon Sep 17 00:00:00 2001 From: Rohit Kini Date: Tue, 16 Jul 2024 14:44:26 +0530 Subject: [PATCH] type ans newstack flag and newstackId in DB --- api/src/models/project-lowdb.ts | 2 + api/src/services/projects.service.ts | 41 +++++++++++++++++++ uplaode-api/src/controllers/sitecore/index.ts | 15 ++++--- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/api/src/models/project-lowdb.ts b/api/src/models/project-lowdb.ts index 233e7f5d..021c17b3 100644 --- a/api/src/models/project-lowdb.ts +++ b/api/src/models/project-lowdb.ts @@ -50,6 +50,8 @@ interface Project { created_at: string; updated_at: string; isDeleted: boolean; + isNewStack: boolean; + newStackId: string; } interface ProjectDocument { diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index 723a8fba..c8159b8e 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -98,6 +98,8 @@ const createProject = async (req: Request) => { updated_at: new Date().toISOString(), created_at: new Date().toISOString(), isDeleted: false, + isNewStack: false, + newStackId: "", }; try { @@ -170,6 +172,10 @@ const updateProject = async (req: Request) => { ProjectModelLowdb.update((data: any) => { data.projects[projectIndex].name = updateData?.name; data.projects[projectIndex].description = updateData?.description; + if(data.projects[projectIndex].isNewStack === false && updateData?.isNewStack === true){ + data.projects[projectIndex].isNewStack = updateData?.isNewStack ; + data.projects[projectIndex].newStackId = updateData?.newStackId; + } data.projects[projectIndex].updated_by = user_id; data.projects[projectIndex].updated_at = new Date().toISOString(); project = data.projects[projectIndex]; @@ -352,6 +358,38 @@ const affixConfirmation = async (req: Request) => { }; }; +const updateNewStack = async (req: Request) => { + const srcFunc = "updateNewStack"; + const { orgId, projectId } = req.params; + const { token_payload } = req.body; + + await ProjectModelLowdb.read(); + const projectIndex = (await getProjectUtil( + projectId, + { + id: projectId, + org_id: orgId, + region: token_payload?.region, + owner: token_payload?.user_id, + }, + srcFunc, + true + )) as number; + + ProjectModelLowdb.update((data: any) => { + data.projects[projectIndex].isNewStack = true; + data.projects[projectIndex].updated_at = new Date().toISOString(); + }); + + return { + status: HTTP_CODES.OK, + data: { + message: HTTP_TEXTS.NEW_STACK_CREATED, + }, + }; +}; + + const updateFileFormat = async (req: Request) => { const { orgId, projectId } = req.params; const { @@ -813,6 +851,8 @@ const revertProject = async (req: Request) => { }; } }; + + export const projectService = { getAllProjects, getProject, @@ -821,6 +861,7 @@ export const projectService = { updateLegacyCMS, updateAffix, affixConfirmation, + updateNewStack, updateFileFormat, fileformatConfirmation, updateDestinationStack, diff --git a/uplaode-api/src/controllers/sitecore/index.ts b/uplaode-api/src/controllers/sitecore/index.ts index 5b8c0549..7bac77c2 100644 --- a/uplaode-api/src/controllers/sitecore/index.ts +++ b/uplaode-api/src/controllers/sitecore/index.ts @@ -23,12 +23,17 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s 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 fileContent = readFileSync(`${infoMap?.path}/global_fields/globalfields.json`, 'utf8'); + const jsonfileContent = JSON.parse(fileContent); + for (const key in jsonfileContent) { + if (jsonfileContent.hasOwnProperty(key)) { + const element = jsonfileContent[key]; + element.type = "global_field"; + } } + fieldMapping.contentTypes.push(jsonfileContent); + const config = { method: 'post', maxBodyLength: Infinity,