Add GET guild settings route

This commit is contained in:
Isaac 2022-05-07 18:41:39 +01:00
parent c082552fae
commit cb4013337f
2 changed files with 9 additions and 5 deletions

View File

@ -111,7 +111,7 @@ model Feedback {
model Guild { model Guild {
autoTag Json? autoTag Json?
archive Boolean @default(true) archive Boolean @default(true)
blocklist Json blocklist Json @default("[]")
categories Category[] categories Category[]
createdAt DateTime @default(now()) createdAt DateTime @default(now())
errorColour String @default("RED") errorColour String @default("RED")

View File

@ -1,7 +1,11 @@
module.exports.get = fastify => ({ module.exports.get = fastify => ({
handler: (req, res) => { handler: async (req, res) => {
const { client } = res.context.config; /** @type {import('../../../../../client')} */
return client.guilds.cache.get(req.params.guild); 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],
}); });