fix(api): move guild delete route to index

This commit is contained in:
Isaac 2025-01-31 16:58:24 +00:00
parent 71547aa142
commit 4278d24e0b
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 23 additions and 22 deletions

View File

@ -1,4 +1,5 @@
/* eslint-disable no-underscore-dangle */ /* eslint-disable no-underscore-dangle */
const { logAdminEvent } = require('../../../../../lib/logging.js');
const { iconURL } = require('../../../../../lib/misc'); const { iconURL } = require('../../../../../lib/misc');
const { const {
getAvgResolutionTime, getAvgResolutionTime,
@ -6,6 +7,28 @@ const {
} = require('../../../../../lib/stats'); } = require('../../../../../lib/stats');
const ms = require('ms'); const ms = require('ms');
module.exports.delete = fastify => ({
handler: async req => {
/** @type {import('client')} */
const client = req.routeOptions.config.client;
const id = req.params.guild;
await client.prisma.guild.delete({ where: { id } });
await client.prisma.guild.create({ data: { id } });
logAdminEvent(client, {
action: 'delete',
guildId: id,
target: {
id,
name: client.guilds.cache.get(id),
type: 'settings',
},
userId: req.user.id,
});
return true;
},
onRequest: [fastify.authenticate, fastify.isAdmin],
});
module.exports.get = fastify => ({ module.exports.get = fastify => ({
handler: async req => { handler: async req => {
/** @type {import("client")} */ /** @type {import("client")} */

View File

@ -1,28 +1,6 @@
const { logAdminEvent } = require('../../../../../lib/logging.js'); const { logAdminEvent } = require('../../../../../lib/logging.js');
const { Colors } = require('discord.js'); const { Colors } = require('discord.js');
module.exports.delete = fastify => ({
handler: async req => {
/** @type {import('client')} */
const client = req.routeOptions.config.client;
const id = req.params.guild;
await client.prisma.guild.delete({ where: { id } });
const settings = await client.prisma.guild.create({ data: { id } });
logAdminEvent(client, {
action: 'delete',
guildId: id,
target: {
id,
name: client.guilds.cache.get(id),
type: 'settings',
},
userId: req.user.id,
});
return settings;
},
onRequest: [fastify.authenticate, fastify.isAdmin],
});
module.exports.get = fastify => ({ module.exports.get = fastify => ({
handler: async req => { handler: async req => {
/** @type {import('client')} */ /** @type {import('client')} */