11// Copyright (c) 2025 The Linux Foundation and each contributor.
22// SPDX-License-Identifier: MIT
33import { fetchFromTinybird } from '~~/server/data/tinybird/tinybird' ;
4- import type { SearchCollection , SearchProject , SearchRepository } from '~~/types/search' ;
4+ import type {
5+ SearchCollection ,
6+ SearchOrganization ,
7+ SearchProject ,
8+ SearchRepository ,
9+ } from '~~/types/search' ;
510import { getRepoNameFromUrl , getRepoSlugFromName } from '~~/server/helpers/repository.helpers' ;
611
712export interface SearchResponse {
813 id : string ;
9- type : 'project' | 'repository' | 'collection' ;
14+ type : 'project' | 'repository' | 'collection' | 'organization' ;
1015 slug : string ;
1116 logo : string | null ;
1217 projectSlug : string | null ;
@@ -20,19 +25,20 @@ export interface SearchResponse {
2025/**
2126 * API Endpoint: /api/search
2227 * Method: GET
23- * Description: Searches for collections, projects, and repositories based on the provided query.
28+ * Description: Searches for collections, projects, repositories, and organizations based on the provided query.
2429 *
2530 * Query Parameters:
26- * - query (string, optional): The search term to query collections, projects, and repositories .
31+ * - query (string, optional): The search term to query collections, projects, repositories, and organizations .
2732 * - limit (number, optional): The maximum number of results to return (default: 10).
2833 *
2934 * Response:
3035 * - projects (Array<SearchResponse>): A list of search results of type "project".
3136 * - repositories (Array<SearchResponse>): A list of search results of type "repository".
3237 * - collections (Array<SearchResponse>): A list of search results of type "collection".
38+ * - organizations (Array<SearchResponse>): A list of search results of type "organization".
3339 *
3440 * Search Response Object (SearchResponse):
35- * - type (string): The type identifier for the search result (e.g., "project", "repository", "collection").
41+ * - type (string): The type identifier for the search result (e.g., "project", "repository", "collection", "organization" ).
3642 * - slug (string): A unique slug identifier for the search result.
3743 * - logo (string | null): The logo URL associated with the search result, or null if unavailable.
3844 * - projectSlug (string | null): The project slug associated with the result, or null if absent.
@@ -48,6 +54,7 @@ export default defineEventHandler(async (event) => {
4854 const projects : SearchProject [ ] = [ ] ;
4955 const repositories : SearchRepository [ ] = [ ] ;
5056 const collections : SearchCollection [ ] = [ ] ;
57+ const organizations : SearchOrganization [ ] = [ ] ;
5158
5259 const limit : number = 10 ;
5360
@@ -86,6 +93,12 @@ export default defineEventHandler(async (event) => {
8693 slug : item . slug ,
8794 name : item . name || '' ,
8895 } ) ;
96+ } else if ( item . type === 'organization' ) {
97+ organizations . push ( {
98+ slug : item . slug ,
99+ name : item . name || '' ,
100+ logo : item . logo ,
101+ } ) ;
89102 }
90103 } ) ;
91104 }
@@ -94,13 +107,15 @@ export default defineEventHandler(async (event) => {
94107 projects,
95108 repositories,
96109 collections,
110+ organizations,
97111 } ;
98112 } catch ( error ) {
99113 console . error ( 'Error fetching search results:' , error ) ;
100114 return {
101115 projects,
102116 repositories,
103117 collections,
118+ organizations,
104119 } ;
105120 }
106121} ) ;
0 commit comments