mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-25 20:50:14 -05:00
builds public api test
This commit is contained in:
57
pages/api/bot/builds.ts
Normal file
57
pages/api/bot/builds.ts
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user