don't create a new category again

This commit is contained in:
Isaac 2022-07-17 23:05:12 +01:00
parent 4a48ba635a
commit c04787bb80

View File

@ -58,38 +58,11 @@ module.exports.patch = fastify => ({
/** @type {import('client')} */ /** @type {import('client')} */
const client = res.context.config.client; const client = res.context.config.client;
const categoryId = Number(req.params.category); const categoryId = Number(req.params.category);
const user = await client.users.fetch(req.user.payload.id);
const guild = client.guilds.cache.get(req.params.guild); const guild = client.guilds.cache.get(req.params.guild);
const data = req.body; const data = req.body;
const allow = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
const original = req.params.category && await client.prisma.category.findUnique({ where: { id: categoryId } }); const original = req.params.category && await client.prisma.category.findUnique({ where: { id: categoryId } });
if (!original) return res.status(404); if (!original) return res.status(404);
if (!data.discordCategory) {
const channel = await guild.channels.create(data.name, {
permissionOverwrites: [
...[
{
deny: ['VIEW_CHANNEL'],
id: guild.roles.everyone,
},
{
allow: allow,
id: client.user.id,
},
],
...data.staffRoles.map(id => ({
allow: allow,
id,
})),
],
position: 1,
reason: `Tickets category created by ${user.tag}`,
type: 'GUILD_CATEGORY',
});
data.discordCategory = channel.id;
}
const category = await client.prisma.category.update({ const category = await client.prisma.category.update({
data: { data: {
...data, ...data,