diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e6abcc5..cbd42cd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -74,7 +74,7 @@ model Category { discordCategory String @db.VarChar(19) emoji String enableFeedback Boolean @default(false) - guild Guild @relation(fields: [guildId], references: [id]) + guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade) guildId String @db.VarChar(19) id Int @id @default(autoincrement()) image String? @@ -161,7 +161,7 @@ model QuestionAnswer { model Tag { content String createdAt DateTime @default(now()) - guild Guild @relation(fields: [guildId], references: [id]) + guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade) guildId String @db.VarChar(19) id Int @id @default(autoincrement()) name String @@ -191,7 +191,7 @@ model Ticket { feedbackId Int? firstResponseAt DateTime? deleted Boolean @default(false) - guild Guild @relation(fields: [guildId], references: [id]) + guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade) guildId String @db.VarChar(19) id String @id @db.VarChar(19) lastMessageAt DateTime? diff --git a/src/routes/api/admin/guilds/[guild]/index.js b/src/routes/api/admin/guilds/[guild]/index.js index 21f8331..fe54f10 100644 --- a/src/routes/api/admin/guilds/[guild]/index.js +++ b/src/routes/api/admin/guilds/[guild]/index.js @@ -1,3 +1,16 @@ +module.exports.delete = fastify => ({ + handler: async (req, res) => { + /** @type {import('../../../../../client')} */ + const client = res.context.config.client; + + await client.prisma.guild.delete({ where: { id: req.params.guild } }); + const settings = await client.prisma.guild.create({ data: { id: req.params.guild } }); + + res.send(settings); + }, + onRequest: [fastify.authenticate, fastify.isAdmin], +}); + module.exports.get = fastify => ({ handler: async (req, res) => { /** @type {import('../../../../../client')} */