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 {
autoTag Json?
archive Boolean @default(true)
blocklist Json
blocklist Json @default("[]")
categories Category[]
createdAt DateTime @default(now())
errorColour String @default("RED")

View File

@ -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],
});