( req: NextApiRequest, res: NextApiResponse, )
| 33 | }; |
| 34 | |
| 35 | const handler = async ( |
| 36 | req: NextApiRequest, |
| 37 | res: NextApiResponse, |
| 38 | ): Promise<void> => { |
| 39 | if (req.method !== 'GET') { |
| 40 | res.status(405).send('Method not allowed'); |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | try { |
| 45 | // Fetch featured squads |
| 46 | const featuredData = await gqlClient.request<SquadsData>(SOURCES_QUERY, { |
| 47 | filterOpenSquads: true, |
| 48 | featured: true, |
| 49 | first: 20, |
| 50 | sortByMembersCount: true, |
| 51 | }); |
| 52 | |
| 53 | // Fetch categories |
| 54 | const categoriesData = await gqlClient.request<CategoriesData>( |
| 55 | SOURCE_CATEGORIES_QUERY, |
| 56 | { first: 20 }, |
| 57 | ); |
| 58 | |
| 59 | const categories = categoriesData.categories.edges.map((edge) => edge.node); |
| 60 | const featuredSquads = featuredData.sources.edges.map((edge) => edge.node); |
| 61 | |
| 62 | // Fetch squads for each category |
| 63 | const categorySquadsPromises = categories.map(async (category) => { |
| 64 | const data = await gqlClient.request<SquadsData>(SOURCES_QUERY, { |
| 65 | filterOpenSquads: true, |
| 66 | categoryId: category.id, |
| 67 | first: 10, |
| 68 | sortByMembersCount: true, |
| 69 | }); |
| 70 | return { |
| 71 | category, |
| 72 | squads: data.sources.edges.map((edge) => edge.node), |
| 73 | }; |
| 74 | }); |
| 75 | |
| 76 | const categorySquads = await Promise.all(categorySquadsPromises); |
| 77 | |
| 78 | const categorySections = categorySquads |
| 79 | .filter(({ squads }) => squads.length > 0) |
| 80 | .map( |
| 81 | ({ category, squads }) => |
| 82 | `### ${escapeMarkdown(category.title)}\n\n${squads |
| 83 | .map(formatSquad) |
| 84 | .join('\n')}`, |
| 85 | ) |
| 86 | .join('\n\n'); |
| 87 | |
| 88 | const markdown = `--- |
| 89 | title: Squads Directory |
| 90 | url: ${appOrigin}/squads/discover |
| 91 | description: Developer communities on daily.dev |
| 92 | --- |
nothing calls this directly
no test coverage detected