mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
29 lines
709 B
JavaScript
Executable File
29 lines
709 B
JavaScript
Executable File
import { Schematized } from "@lib"
|
|
import { Badge } from "@db_models"
|
|
|
|
export default {
|
|
method: "GET",
|
|
route: "/",
|
|
fn: Schematized({
|
|
select: ["_id", "name", "label"],
|
|
}, async (req, res) => {
|
|
let badges = []
|
|
|
|
if (req.selection._id) {
|
|
badges = await Badge.find({
|
|
_id: { $in: req.selection._id },
|
|
})
|
|
|
|
badges = badges.map(badge => badge.toObject())
|
|
} else {
|
|
badges = await Badge.find(req.selection).catch((err) => {
|
|
res.status(500).json({ error: err })
|
|
return false
|
|
})
|
|
}
|
|
|
|
if (badges) {
|
|
return res.json(badges)
|
|
}
|
|
})
|
|
} |