Increased power of tree searching

This commit is contained in:
Stefan Zermatten
2023-06-26 14:45:19 +02:00
parent d4cac831e6
commit 7562e29fac
8 changed files with 205 additions and 63 deletions

View File

@@ -203,22 +203,42 @@ let libraryIdSchema = new SimpleSchema({
},
});
Meteor.publish('libraryNodes', function (libraryId) {
const extraFieldsSchema = new SimpleSchema({
extraFields: {
type: Array,
optional: true,
},
'extraFields.$': {
type: String,
},
});
Meteor.publish('libraryNodes', function (libraryId, extraFields) {
if (!libraryId) return [];
libraryIdSchema.validate({ libraryId });
try {
libraryIdSchema.validate({ libraryId });
extraFieldsSchema.validate({ extraFields });
} catch (e) {
return this.error(e);
}
this.autorun(function () {
let userId = this.userId;
let library = Libraries.findOne(libraryId);
try { assertViewPermission(library, userId) }
catch (e) {
try {
assertViewPermission(library, userId)
} catch (e) {
return this.error(e);
}
const fields = { ...LIBRARY_NODE_TREE_FIELDS };
extraFields?.forEach(field => {
fields[field] = 1;
});
return [
LibraryNodes.find({
'ancestors.id': libraryId,
}, {
sort: { order: 1 },
fields: LIBRARY_NODE_TREE_FIELDS,
fields,
}),
];
});