mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
transformed metadata into a boolean
This commit is contained in:
parent
e2fb4e2fed
commit
2be701f2e3
2 changed files with 1 additions and 71 deletions
|
@ -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: {
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Add table
Reference in a new issue