diff --git a/app/controllers/api/v1/Misc.controller.js b/app/controllers/api/v1/Misc.controller.js index 504e7a6..9dec1ad 100644 --- a/app/controllers/api/v1/Misc.controller.js +++ b/app/controllers/api/v1/Misc.controller.js @@ -33,6 +33,7 @@ class Misc extends Controller { const Page = this.models.get('api:Page') const Node = this.models.get('api:Node') 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 results = [] @@ -75,6 +76,7 @@ class Misc extends Controller { } const matching_codiums = await Codium.find({ + Active: true, PageId: { $in: all_user_page_ids }, $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}) } }