mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Merge pull request #6800 from kirrg001/fix/null-problem
fix: delete null values from incoming objects
This commit is contained in:
commit
2744fed5d8
2 changed files with 28 additions and 0 deletions
|
@ -283,6 +283,15 @@ utils = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// will remove unwanted null values
|
||||||
|
_.each(object[docName], function (value, index) {
|
||||||
|
if (!_.isObject(object[docName][index])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
object[docName][index] = _.omit(object[docName][index], _.isNull);
|
||||||
|
});
|
||||||
|
|
||||||
if (editId && object[docName][0].id && parseInt(editId, 10) !== parseInt(object[docName][0].id, 10)) {
|
if (editId && object[docName][0].id && parseInt(editId, 10) !== parseInt(object[docName][0].id, 10)) {
|
||||||
return errors.logAndRejectError(new errors.BadRequestError(i18n.t('errors.api.utils.invalidIdProvided')));
|
return errors.logAndRejectError(new errors.BadRequestError(i18n.t('errors.api.utils.invalidIdProvided')));
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,6 +370,25 @@ describe('API Utils', function () {
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('will delete null values from object', function (done) {
|
||||||
|
var object = {test: [{id: 1, key: null}]};
|
||||||
|
|
||||||
|
apiUtils.checkObject(_.cloneDeep(object), 'test').then(function (data) {
|
||||||
|
should.not.exist(data.test[0].key);
|
||||||
|
should.exist(data.test[0].id);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will not break if the expected object is a string', function (done) {
|
||||||
|
var object = {test: ['something']};
|
||||||
|
|
||||||
|
apiUtils.checkObject(_.cloneDeep(object), 'test').then(function (data) {
|
||||||
|
data.test[0].should.eql('something');
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('checkFileExists', function () {
|
describe('checkFileExists', function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue