Allow searching databases by name (#6)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-10-13 10:23:58 -05:00
parent 597c269cd9
commit 5b0692d85d
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -33,6 +33,7 @@ class Misc extends Controller {
const Page = this.models.get('api:Page') const Page = this.models.get('api:Page')
const Node = this.models.get('api:Node') const Node = this.models.get('api:Node')
const Codium = this.models.get('api:Codium') const Codium = this.models.get('api:Codium')
const Database = this.models.get('api:db:Database')
const all_user_page_ids = (await req.user.get_accessible_pages()).map(x => x.UUID) const all_user_page_ids = (await req.user.get_accessible_pages()).map(x => x.UUID)
const results = [] const results = []
@ -75,6 +76,7 @@ class Misc extends Controller {
} }
const matching_codiums = await Codium.find({ const matching_codiums = await Codium.find({
Active: true,
PageId: { $in: all_user_page_ids }, PageId: { $in: all_user_page_ids },
$text: { $search: query }, $text: { $search: query },
}); });
@ -95,6 +97,28 @@ class Misc extends Controller {
}) })
} }
const matching_dbs = await Database.find({
Active: true,
PageId: { $in: all_user_page_ids },
$text: { $search: query },
})
for ( const db of matching_dbs ) {
const page = await db.page
results.push({
title: db.Name,
short_title: `${db.Name.slice(0, snip_length)}${db.Name.length > snip_length ? '...' : ''}`,
type: 'db',
id: db.NodeId,
associated: {
title: page.Name,
short_title: `${page.Name.slice(0, snip_length)}${page.Name.length > snip_length ? '...' : ''}`,
type: 'page',
id: page.UUID,
}
})
}
return res.api({results}) return res.api({results})
} }
} }