diff --git a/model/projectDAO.js b/model/projectDAO.js index 1f98dad..86bc0a0 100644 --- a/model/projectDAO.js +++ b/model/projectDAO.js @@ -104,7 +104,14 @@ module.exports = { } }); }, - + addUpdateChildInSingleLevelProject: async (projectId, childId,childData) => { + return await mongo.Projects.updateOne({ _id: new ObjectId(projectId),"sections._id":ObjectId(childId) }, { + $set: { + "sections.$": childData + } + },{upsert:true} + ); +}, addUpdateProjectChild : async (projectId, childId, childData)=>{ return await mongo.Projects.findOneAndUpdate({_id:ObjectId(projectId),"children._id":ObjectId(childId)}, { diff --git a/service/sectionService.js b/service/sectionService.js index 8642c1f..ada9c65 100644 --- a/service/sectionService.js +++ b/service/sectionService.js @@ -149,7 +149,7 @@ const editSetion = async (sectionId, section) => { // sectionId, // sectionFromDB // ); - await updateParentHelper.addUpdateSectionMetadataFromParent( + await updateParentHelper.addUpdateSectionMetadataInParent( sectionId, sectionFromDB ); diff --git a/service/subProjectService.js b/service/subProjectService.js index 5fd5998..c2d641c 100644 --- a/service/subProjectService.js +++ b/service/subProjectService.js @@ -154,7 +154,7 @@ const editSubProject = async (subProjectId,subproject) => { //await updateParentHelper.removeSubprojectMetaDataInProject(subProjectId,subProjectFromDB); //await updateParentHelper.addSubprojectMetaDataInProject(subProjectId,subProjectFromDB); - await updateParentHelper.addRemoveSubProjectMetadataInProject(subProjectId,subProjectFromDB); + await updateParentHelper.addUpdateSubProjectMetadataInProject(subProjectId,subProjectFromDB); return { success: true, }; diff --git a/service/updateParentHelper.js b/service/updateParentHelper.js index 93e0497..9d019c4 100644 --- a/service/updateParentHelper.js +++ b/service/updateParentHelper.js @@ -138,7 +138,7 @@ const removeSectionMetadataFromParent = async (sectionId, section) => { ); } }; -const addUpdateSectionMetadataFromParent = async (sectionId,section)=>{ +const addUpdateSectionMetadataInParent = async (sectionId,section)=>{ const sectionDataInParent = { _id:sectionId, name: section.name, @@ -154,7 +154,7 @@ const addUpdateSectionMetadataFromParent = async (sectionId,section)=>{ }; if (section.parenttype == "project") { - await ProjectDAO.addChildInSingleLevelProject( + await ProjectDAO.addUpdateChildInSingleLevelProject ( section.parentid, sectionId, sectionDataInParent @@ -218,7 +218,7 @@ const removeSubprojectMetaDataInProject = async (subProjectId, subProject) => { ); }; -const addRemoveSubProjectMetadataInProject = async (subProjectId, subProject) => { +const addUpdateSubProjectMetadataInProject = async (subProjectId, subProject) => { const subProjectDataInParent = { _id: subProject._id, name: subProject.name, @@ -242,8 +242,8 @@ module.exports = { removeSectionMetadataFromParent, addSubprojectMetaDataInProject, removeSubprojectMetaDataInProject, - addRemoveSubProjectMetadataInProject, + addUpdateSubProjectMetadataInProject, addUpdateLocationMetadataInParent, - addUpdateSectionMetadataFromParent, + addUpdateSectionMetadataInParent, addUpdateSubprojectMetaDataInProject };