Skip to content

Commit 9896462

Browse files
author
Vikas Agarwal
committed
Trying to fix the merge of priceConfig. It should just override the complete JSON.
1 parent 8559af1 commit 9896462

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/routes/projectTemplates/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = [
6464
}
6565

6666
// Merge JSON fields
67-
entityToUpdate.scope = util.mergeJsonObjects(projectTemplate.scope, entityToUpdate.scope);
67+
entityToUpdate.scope = util.mergeJsonObjects(projectTemplate.scope, entityToUpdate.scope, ['priceConfig']);
6868
entityToUpdate.phases = util.mergeJsonObjects(projectTemplate.phases, entityToUpdate.phases);
6969
// removes null phase templates
7070
entityToUpdate.phases = _.omitBy(entityToUpdate.phases, _.isNull);

src/util.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,13 @@ _.assignIn(util, {
379379
* Merge two JSON objects. For array fields, the target will be replaced by source.
380380
* @param {Object} targetObj the target object
381381
* @param {Object} sourceObj the source object
382+
* @param {Object} mergeExceptions list of keys which should be exempted from merge
382383
* @returns {Object} the merged object
383384
*/
384385
// eslint-disable-next-line consistent-return
385-
mergeJsonObjects: (targetObj, sourceObj) => _.mergeWith(targetObj, sourceObj, (target, source) => {
386-
// Overwrite the array
387-
if (_.isArray(source)) {
386+
mergeJsonObjects: (targetObj, sourceObj, mergeExceptions) => _.mergeWith(targetObj, sourceObj, (target, source, key) => {
387+
// Overwrite the array or merge exception keys
388+
if (_.isArray(source) || (mergeExceptions && mergeExceptions.indexOf(key) !== -1)) {
388389
return source;
389390
}
390391
}),

0 commit comments

Comments
 (0)