From fdec3cd45533b0298f409b7654f1944dd6f0ee6b Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Fri, 15 Jan 2021 23:25:04 +0200 Subject: [PATCH] builds public api test --- pages/api/bot/builds.ts | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 pages/api/bot/builds.ts diff --git a/pages/api/bot/builds.ts b/pages/api/bot/builds.ts new file mode 100644 index 000000000..01ad280dc --- /dev/null +++ b/pages/api/bot/builds.ts @@ -0,0 +1,57 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import prisma from "prisma/client"; + +const buildsBotHandler = async (req: NextApiRequest, res: NextApiResponse) => { + if (req.method !== "GET") { + return res.status(405).end(); + } + + const weapon = + typeof req.query.weapon === "string" ? req.query.weapon : undefined; + const discordId = + typeof req.query.discordId === "string" ? req.query.discordId : undefined; + + if (weapon && discordId) { + return res + .status(400) + .json({ message: "Choose either discordId or weapon not both." }); + } + if (!weapon && !discordId) { + return res + .status(400) + .json({ message: "Include discordId or weapon as query parameter." }); + } + + const builds = await prisma.build.findMany({ + where: weapon ? { weapon } : { user: { discordId } }, + select: { + abilityPoints: true, + clothingAbilities: true, + clothingGear: true, + description: true, + headAbilities: true, + headGear: true, + id: true, + jpn: true, + modes: true, + shoesAbilities: true, + shoesGear: true, + title: true, + top500: true, + updatedAt: true, + weapon: true, + user: { + select: { + discordId: true, + discriminator: true, + username: true, + }, + }, + }, + orderBy: [{ top500: "desc" }, { jpn: "desc" }, { updatedAt: "desc" }], + }); + + res.status(200).json(builds); +}; + +export default buildsBotHandler;