import { Router } from 'express' import Finish from '../schemas/Finish.js' const finishApi = Router() finishApi.get( '/count', (req, res) => { Finish.find({}).count().then( finishAmount => { res.json({ success: true, response: finishAmount }) } ) } ) finishApi.get( '/find', async (req, res) => { if (!req.query.player && !req.query.map) return res.json({ success: false, response: "Please provide either a player or map!" }) const player = req.query.player const map = req.query.map const sort = req.query.sort ?? 'date' const order = req.query.order === "desc" ? -1 : 1 Finish.find({ player: player ?? /\w/, map: map ?? /\w/ }).sort([[sort, order]]).then( finishes => { if (!finishes[0]) return res.json({ success: false, response: "No maps found!" }) res.json({ success: true, response: { finishes } }) } ) } ) /** * This module handles all API actions related to maps. * @module api/finishes */ export default finishApi