import axios from 'axios'; import type { MSCCRawEvent } from '$types/Events'; import type { MSCCRawTour } from '$types/Tours'; /** * Fetches items from the MSCC API * @param API_URL The URL of the API to fetch items from * @returns MSCCRawEvent[] | MSCCRawTour[] */ export async function fetchItems(API_URL: string): Promise { // Set up the request dates const currentDate = new Date(); const startDate = currentDate.toLocaleDateString('en-US').split('/').join('-'); const endDate = new Date( currentDate.getFullYear() + 1, currentDate.getMonth(), currentDate.getDate() ) .toLocaleDateString('en-US') .split('/') .join('-'); let allItems: any = []; try { // Fetch the items from the API from a POST request with a JSON body const response = await axios.post(API_URL, { StartDate: startDate, EndDate: endDate, }); allItems = await response.data; } catch (error) { // If there's an error fetching items, log it and return false console.error('Error fetching items:', error); } return allItems; }