All checks were successful
Lint and Build / build (pull_request) Successful in 2m47s
- Remove unused NextResponse imports from API routes - Remove unused result variable in teams DELETE route - Remove unused Link import from page.tsx - Remove unused inspectTextSourceProperties function from obsClient.js - Fix unused catch variables and response variables in test files - Clean up all ESLint warnings for unused variables
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { NextRequest } from 'next/server';
|
|
import { getDatabase } from '../../../lib/database';
|
|
import { TABLE_NAMES } from '../../../lib/constants';
|
|
import { createErrorResponse, createSuccessResponse, createDatabaseError, withErrorHandling } from '../../../lib/apiHelpers';
|
|
|
|
async function getTeamNameHandler(request: NextRequest) {
|
|
// Extract the team_id from the query string
|
|
const { searchParams } = new URL(request.url);
|
|
const teamId = searchParams.get('team_id');
|
|
|
|
if (!teamId) {
|
|
return createErrorResponse('Missing team_id', 400, 'team_id parameter is required');
|
|
}
|
|
|
|
try {
|
|
const db = await getDatabase();
|
|
const team = await db.get(
|
|
`SELECT team_name FROM ${TABLE_NAMES.TEAMS} WHERE team_id = ?`,
|
|
[teamId]
|
|
);
|
|
|
|
if (!team) {
|
|
return createErrorResponse('Team not found', 404, `No team found with ID: ${teamId}`);
|
|
}
|
|
|
|
return createSuccessResponse({ team_name: team.team_name });
|
|
} catch (error) {
|
|
return createDatabaseError('fetch team name', error);
|
|
}
|
|
}
|
|
|
|
export const GET = withErrorHandling(getTeamNameHandler);
|