The convertToOldFormat function transforms data from the new NCAA GraphQL endpoint into a legacy format used by older versions of the API.
It performs several key tasks:
- Data Normalization: Maps
gameState values (e.g., 'F' to 'final', 'P' to 'pre', 'I' to 'live'). - Legacy Enrichment: If the requested year is before 2025 and the sport is not basketball or football, it attempts to fetch supplemental data from the old
data.ncaa.com endpoint to fill in missing fields like fullName, description, and conferenceName. - Time Formatting: Converts
startTime into a human-readable string (e.g., "12:00PM ET"). - Checksum Generation: Produces an
inputMD5Sum of the games data for backwards compatibility.
Parameters:
newData: The GraphQLResponse from fetchGqlScoreboard.sport: The sport string.division: The division string.date: The date string.year: The year as a number.
Returns: An object containing inputMD5Sum, instanceId, updated_at, and an array of games in the legacy structure.
import { fetchGqlScoreboard, convertToOldFormat } from './scoreboard/scoreboard';
const newData = await fetchGqlScoreboard(params);
const oldFormat = await convertToOldFormat(
newData,
'football',
'd1',
'2024-11-23',
2024
);