2021-10-30 20:26:37 +02:00
|
|
|
import { Router } from 'express'
|
2021-11-04 15:40:12 +01:00
|
|
|
import wrapper from '../libs/database/wrapper.js'
|
2021-10-30 20:26:37 +02:00
|
|
|
|
|
|
|
const playerApi = Router()
|
|
|
|
|
|
|
|
playerApi.get(
|
|
|
|
'/get/:player',
|
|
|
|
async (req, res) => {
|
2021-11-04 15:40:12 +01:00
|
|
|
/* Check if player exists */
|
|
|
|
if(!wrapper.playerExists(req.params.player)) {
|
|
|
|
return res.json({
|
2021-11-02 11:32:59 +01:00
|
|
|
success: false,
|
2021-11-04 15:40:12 +01:00
|
|
|
response: "No such player!"
|
2021-11-02 11:32:59 +01:00
|
|
|
})
|
2021-11-04 15:40:12 +01:00
|
|
|
}
|
|
|
|
const data = wrapper.player(req.params.player)
|
|
|
|
|
|
|
|
return res.json({
|
|
|
|
success: true,
|
|
|
|
response: data
|
|
|
|
})
|
2021-10-30 20:26:37 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
playerApi.get(
|
|
|
|
'/search',
|
|
|
|
async (req, res) => {
|
|
|
|
if (!req.query.q) {
|
|
|
|
return res.json({
|
|
|
|
success: false,
|
2021-11-02 11:32:59 +01:00
|
|
|
response: "No query ('?q=query') provided!"
|
2021-10-30 20:26:37 +02:00
|
|
|
})
|
|
|
|
}
|
2021-11-02 11:32:59 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
)
|
2021-10-30 20:26:37 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export default playerApi
|