All files / src/api shuttleScheduleApi.ts

100% Statements 13/13
100% Branches 8/8
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                            3x 1x     2x   2x 1x     1x       4x 1x     3x   3x 1x     2x 2x    
import { API_BASE_URL } from "../const";
 
export interface ShuttleSchedule {
  campus: string;
  dayType: string;
  departureTimes: string[];
}
 
export interface ShuttleScheduleResponse {
  schedules: ShuttleSchedule[];
  version: number;
}
 
export async function getShuttleSchedule(): Promise<ShuttleScheduleResponse> {
  if (!API_BASE_URL) {
    throw new Error("API_BASE_URL is not defined");
  }
 
  const response = await fetch(`${API_BASE_URL}/api/shuttle/schedule`);
 
  if (!response.ok) {
    throw new Error(`Shuttle schedule API error: ${response.status}`);
  }
 
  return response.json();
}
 
export async function getShuttleVersion(): Promise<number> {
  if (!API_BASE_URL) {
    throw new Error("API_BASE_URL is not defined");
  }
 
  const response = await fetch(`${API_BASE_URL}/api/shuttle/version`);
 
  if (!response.ok) {
    throw new Error(`Shuttle version API error: ${response.status}`);
  }
 
  const json = await response.json();
  return json.version;
}