mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 09:23:07 +02:00
Add GET & POST guild categories routes
This commit is contained in:
parent
66b46cf3e2
commit
41ccd778c6
@ -84,7 +84,7 @@ model Category {
|
|||||||
pingRoles Json @default("[]")
|
pingRoles Json @default("[]")
|
||||||
questions Question[]
|
questions Question[]
|
||||||
ratelimit Int?
|
ratelimit Int?
|
||||||
requiredRoles Json
|
requiredRoles Json @default("[]")
|
||||||
requireTopic Boolean @default(false)
|
requireTopic Boolean @default(false)
|
||||||
staffRoles Json
|
staffRoles Json
|
||||||
tickets Ticket[]
|
tickets Ticket[]
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
module.exports.get = fastify => ({
|
||||||
|
handler: async (req, res) => {
|
||||||
|
/** @type {import('../../../../../../client')} */
|
||||||
|
const client = res.context.config.client;
|
||||||
|
|
||||||
|
const categories = await client.prisma.guild.findUnique({ where: { id: req.params.guild } }).categories();
|
||||||
|
|
||||||
|
res.send(categories);
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports.post = fastify => ({
|
||||||
|
handler: async (req, res) => {
|
||||||
|
/** @type {import('../../../../../../client')} */
|
||||||
|
const client = res.context.config.client;
|
||||||
|
|
||||||
|
const user = await client.users.fetch(req.user.payload.id);
|
||||||
|
const guild = client.guilds.cache.get(req.params.guild);
|
||||||
|
const data = req.body;
|
||||||
|
const allow = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
|
||||||
|
|
||||||
|
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.create({
|
||||||
|
data: {
|
||||||
|
guild: { connect: { id: guild.id } },
|
||||||
|
...data,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send(category);
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user