Drunk-Venti-Api/pages/api/events/current.js
2022-01-15 18:07:08 +01:00

13 lines
No EOL
476 B
JavaScript

import {compareEndTimes, isCurrentEvent} from "../../../utils/time";
import {getEvents} from "./utils";
export default async function currentEvents(req, res){
const allEvents = await getEvents();
let currents = allEvents.flat().map(isCurrentEvent).filter(x=>x);
currents = currents.sort(compareEndTimes);
if (currents) {
res.status(200).json(currents);
} else {
res.status(404).json({message: "There is no event currently going"});
}
}