From f2c189eefcc2eb7f20865bb0b99f8db358a00b0a Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 16 Aug 2018 11:50:21 +0530 Subject: [PATCH 1/6] Added missing field in the SQL script --- migrations/20180608_project_add_templateId_and_new_tables.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/migrations/20180608_project_add_templateId_and_new_tables.sql b/migrations/20180608_project_add_templateId_and_new_tables.sql index 5b1ede10..3f3d6723 100644 --- a/migrations/20180608_project_add_templateId_and_new_tables.sql +++ b/migrations/20180608_project_add_templateId_and_new_tables.sql @@ -113,6 +113,7 @@ CREATE TABLE product_milestone_templates ( "activeText" character varying(512) NOT NULL, "blockedText" character varying(512) NOT NULL, "completedText" character varying(512) NOT NULL, + "hidden" boolean DEFAULT false, "deletedAt" timestamp with time zone, "createdAt" timestamp with time zone, "updatedAt" timestamp with time zone, From 8ad15d5b4940900c6e7328399145263fe579f824 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 16 Aug 2018 11:51:39 +0530 Subject: [PATCH 2/6] Trying to unset a key if source has it as null --- src/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util.js b/src/util.js index 79cecbc3..6895d781 100644 --- a/src/util.js +++ b/src/util.js @@ -384,6 +384,9 @@ _.assignIn(util, { if (_.isArray(source)) { return source; } + if (source === null) { + _.unset(destination, key); + } }), }); From 1340cb907d322756c470f15bc5b049de9bc43dfd Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 16 Aug 2018 12:03:48 +0530 Subject: [PATCH 3/6] lint fixes --- src/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.js b/src/util.js index 6895d781..f8fe5885 100644 --- a/src/util.js +++ b/src/util.js @@ -379,13 +379,13 @@ _.assignIn(util, { * @returns {Object} the merged object */ // eslint-disable-next-line consistent-return - mergeJsonObjects: (targetObj, sourceObj) => _.mergeWith(targetObj, sourceObj, (target, source) => { + mergeJsonObjects: (targetObj, sourceObj) => _.mergeWith(targetObj, sourceObj, (target, source, key) => { // Overwrite the array if (_.isArray(source)) { return source; } if (source === null) { - _.unset(destination, key); + _.unset(target, key); } }), }); From 49249db52c99f277ff6632b966253bb8325cca90 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 16 Aug 2018 12:37:45 +0530 Subject: [PATCH 4/6] trying to skip null phase as temporary hack for not being able to delete old phase templates in project templates --- src/routes/projects/create.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/projects/create.js b/src/routes/projects/create.js index c603b820..b83fb4ea 100644 --- a/src/routes/projects/create.js +++ b/src/routes/projects/create.js @@ -87,7 +87,7 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates) if (!projectTemplate) { return Promise.resolve(result); } - const phases = _.values(projectTemplate.phases); + const phases = _.filter(_.values(projectTemplate.phases), p => !!p); const productTemplateMap = {}; productTemplates.forEach((pt) => { productTemplateMap[pt.id] = pt; From f7b931ceceee77e6d300cc29909505072c7756ec Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 16 Aug 2018 12:42:00 +0530 Subject: [PATCH 5/6] Removes null values from phases key of project templates --- src/routes/projectTemplates/update.js | 2 ++ src/util.js | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/routes/projectTemplates/update.js b/src/routes/projectTemplates/update.js index 61e01c99..d7b61c0f 100644 --- a/src/routes/projectTemplates/update.js +++ b/src/routes/projectTemplates/update.js @@ -66,6 +66,8 @@ module.exports = [ // Merge JSON fields entityToUpdate.scope = util.mergeJsonObjects(projectTemplate.scope, entityToUpdate.scope); entityToUpdate.phases = util.mergeJsonObjects(projectTemplate.phases, entityToUpdate.phases); + // removes null phase templates + entityToUpdate.phases = _.omitBy(entityToUpdate.phases, _.isNull) return projectTemplate.update(entityToUpdate); }) diff --git a/src/util.js b/src/util.js index f8fe5885..79cecbc3 100644 --- a/src/util.js +++ b/src/util.js @@ -379,14 +379,11 @@ _.assignIn(util, { * @returns {Object} the merged object */ // eslint-disable-next-line consistent-return - mergeJsonObjects: (targetObj, sourceObj) => _.mergeWith(targetObj, sourceObj, (target, source, key) => { + mergeJsonObjects: (targetObj, sourceObj) => _.mergeWith(targetObj, sourceObj, (target, source) => { // Overwrite the array if (_.isArray(source)) { return source; } - if (source === null) { - _.unset(target, key); - } }), }); From 67c5d408e98168b799b0d5a4a6fcc3a7dae45f3b Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Thu, 16 Aug 2018 12:42:59 +0530 Subject: [PATCH 6/6] lint fix --- src/routes/projectTemplates/update.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/projectTemplates/update.js b/src/routes/projectTemplates/update.js index d7b61c0f..0e048afe 100644 --- a/src/routes/projectTemplates/update.js +++ b/src/routes/projectTemplates/update.js @@ -67,7 +67,7 @@ module.exports = [ entityToUpdate.scope = util.mergeJsonObjects(projectTemplate.scope, entityToUpdate.scope); entityToUpdate.phases = util.mergeJsonObjects(projectTemplate.phases, entityToUpdate.phases); // removes null phase templates - entityToUpdate.phases = _.omitBy(entityToUpdate.phases, _.isNull) + entityToUpdate.phases = _.omitBy(entityToUpdate.phases, _.isNull); return projectTemplate.update(entityToUpdate); })