transformed metadata into a boolean

This commit is contained in:
Theodor Diaconu 2017-11-23 21:03:39 +02:00
parent e2fb4e2fed
commit 2be701f2e3
2 changed files with 1 additions and 71 deletions

View file

@ -14,12 +14,7 @@ export default new SimpleSchema({
optional: true
},
metadata: {
type: null,
blackbox: true,
optional: true
},
metadataIdField: {
type: String,
type: Boolean,
optional: true
},
inversedBy: {

View file

@ -1,65 +0,0 @@
/**
* Actually attaches the field schema
*
* @returns {boolean}
* @private
*/
export default (collection, {metadata, field}, isMany) => {
if (metadata) {
if (_.keys(metadata).length) {
const schema = constructMetadataSchema(field, isMany, metadata);
if (isMany) {
collection.attachSchema({
[field]: {type: Array, optional: true},
[field + '.$']: {type: Object},
...schema
})
} else {
collection.attachSchema({
[field]: {type: schema},
...schema
})
}
} else {
if (isMany) {
collection.attachSchema({
[field]: {type: Array, optional: true},
[field + '.$']: {type: Object, blackbox: true}
});
} else {
collection.attachSchema({
[field]: {type: Object, blackbox: true, optional: true}
});
}
}
} else {
if (isMany) {
collection.attachSchema({
[field]: {type: Array, optional: true},
[field + '.$']: {type: String},
})
} else {
collection.attachSchema({
[field]: {
type: String,
optional: true
}
})
}
}
}
function constructMetadataSchema(field, isMany, metadataSchema) {
let suffix = isMany ? '.$' : '';
let schemaDefinition = {
[field + suffix + `._id`]: {type: String}
};
_.each(metadataSchema, (value, key) => {
schemaDefinition[field + suffix + '.' + key] = value;
});
return schemaDefinition;
}