Fix schema handler set disgarding falsy values

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-07-28 18:34:14 +02:00 committed by Pierre Noël
parent f12a696824
commit 38d896f0ea
3 changed files with 10 additions and 14 deletions

View File

@ -77,13 +77,15 @@ module.exports = function createComponentBuilder() {
.setUID(uid)
.set('kind', infos.kind || typeKinds.COLLECTION_TYPE)
.set('collectionName', infos.collectionName || defaultCollectionName)
.set(['info', 'name'], infos.name)
.set(['info', 'description'], infos.description)
.set('info', {
name: infos.name,
description: infos.description,
})
.set('options', {
increments: true,
timestamps: true,
draftAndPublish: infos.draftAndPublish || false,
})
.setOption('draftAndPublish', infos.draftAndPublish || false)
.setAttributes(this.convertAttributes(infos.attributes));
Object.keys(infos.attributes).forEach(key => {
@ -185,7 +187,7 @@ module.exports = function createComponentBuilder() {
.set('kind', infos.kind || contentType.schema.kind)
.set(['info', 'name'], infos.name)
.set(['info', 'description'], infos.description)
.setOption('draftAndPublish', infos.draftAndPublish || false)
.set(['options', 'draftAndPublish'], infos.draftAndPublish || false)
.setAttributes(this.convertAttributes(newAttributes));
return contentType;

View File

@ -76,15 +76,6 @@ module.exports = function createSchemaHandler(infos) {
return this;
},
// Set a particular option inside the schema
setOption(path, val) {
modified = true;
_.set(state.schema, ['options'].concat(path), val);
return this;
},
// get a particuar path inside the schema
get(path) {
return _.get(state.schema, path);
@ -94,7 +85,8 @@ module.exports = function createSchemaHandler(infos) {
set(path, val) {
modified = true;
_.set(state.schema, path, val || _.get(state.schema, path));
const value = _.defaultTo(val, _.get(state.schema, path));
_.set(state.schema, path, value);
return this;
},

View File

@ -13,6 +13,7 @@ Object {
"collectionName": "test_collection_types",
"connection": "default",
"description": "",
"draftAndPublish": false,
"kind": "collectionType",
"name": "Test Collection Type",
},
@ -34,6 +35,7 @@ Object {
"collectionName": "test_single_types",
"connection": "default",
"description": "",
"draftAndPublish": false,
"kind": "singleType",
"name": "Test Single Type",
},