From cb4013337f087c0d363deebce04e443fb8351e4e Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 7 May 2022 18:41:39 +0100 Subject: [PATCH] Add GET guild settings route --- prisma/schema.prisma | 2 +- src/routes/api/admin/guilds/[guild]/index.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index aa7c14e..ecf4641 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -111,7 +111,7 @@ model Feedback { model Guild { autoTag Json? archive Boolean @default(true) - blocklist Json + blocklist Json @default("[]") categories Category[] createdAt DateTime @default(now()) errorColour String @default("RED") diff --git a/src/routes/api/admin/guilds/[guild]/index.js b/src/routes/api/admin/guilds/[guild]/index.js index 6dff4d6..df98bcd 100644 --- a/src/routes/api/admin/guilds/[guild]/index.js +++ b/src/routes/api/admin/guilds/[guild]/index.js @@ -1,7 +1,11 @@ module.exports.get = fastify => ({ - handler: (req, res) => { - const { client } = res.context.config; - return client.guilds.cache.get(req.params.guild); + handler: async (req, res) => { + /** @type {import('../../../../../client')} */ + const client = res.context.config.client; + + const settings = await client.prisma.guild.findUnique({ where: { id: req.params.guild } }) ?? + await client.prisma.guild.create({ data: { id: req.params.guild } }); + res.send(settings); }, - onRequest: [fastify.authenticate], + onRequest: [fastify.authenticate, fastify.isAdmin], }); \ No newline at end of file