import { Router } from 'express' import wrapper from '../libs/database/wrapper.js' const playerApi = Router() playerApi.get( '/get/:player', async (req, res) => { /* Check if player exists */ if(!wrapper.playerExists(req.params.player)) { return res.json({ success: false, response: "No such player!" }) } const data = wrapper.player(req.params.player) return res.json({ success: true, response: data }) } ) playerApi.get( '/search', async (req, res) => { if (!req.query.q) { return res.json({ success: false, response: "No query ('?q=query') provided!" }) } searcher( 'points', 'player', `%${req.query.q}%`, req.query.sort ?? undefined, req.query.order === "asc", "all", req.query.page ).then( player => res.json({ success: true, response: player }) ).catch( error => res.json({ success: false, response: error }) ) } ) export default playerApi