From b00d2f312eb0e3353213a1ebdcf28002342640ec Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 3 Jul 2024 02:03:16 +0100 Subject: [PATCH] feat(api): something --- src/routes/api/guilds/[guild]/index.js | 1 - src/routes/api/guilds/[guild]/tickets/@me.js | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/routes/api/guilds/[guild]/tickets/@me.js diff --git a/src/routes/api/guilds/[guild]/index.js b/src/routes/api/guilds/[guild]/index.js index eb854d5..e3fe35c 100644 --- a/src/routes/api/guilds/[guild]/index.js +++ b/src/routes/api/guilds/[guild]/index.js @@ -5,7 +5,6 @@ module.exports.get = fastify => ({ handler: async (req, res) => { const { client } = req.routeOptions.config; const guild = client.guilds.cache.get(req.params.guild); - if (!guild) return res.status(404).send(new Error('Not Found')); res.send({ id: guild.id, logo: iconURL(guild), diff --git a/src/routes/api/guilds/[guild]/tickets/@me.js b/src/routes/api/guilds/[guild]/tickets/@me.js new file mode 100644 index 0000000..d80e078 --- /dev/null +++ b/src/routes/api/guilds/[guild]/tickets/@me.js @@ -0,0 +1,18 @@ +module.exports.get = fastify => ({ + handler: async (req, res) => { + const { client } = req.routeOptions.config; + /** @type {import("@prisma/client").PrismaClient} */ + const prisma = client.prisma; + const guild = client.guilds.cache.get(req.params.guild); + res.send( + await prisma.ticket.findMany({ + where: { + createdById: req.user.id, + guildId: guild.id, + }, + }), + ); + }, + onRequest: [fastify.authenticate, fastify.isMember], +}); +