mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
Closes #321
This commit is contained in:
parent
954681685a
commit
cdb8fa04c4
@ -1,33 +1,44 @@
|
||||
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||
const emoji = require('node-emoji');
|
||||
const { ChannelType: { GuildCategory } } = require('discord.js');
|
||||
const ms = require('ms');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
/** @type {import('client')} */
|
||||
const client = res.context.config.client;
|
||||
|
||||
const { categories } = await client.prisma.guild.findUnique({
|
||||
select: { categories: true },
|
||||
let { categories } = await client.prisma.guild.findUnique({
|
||||
select: {
|
||||
categories: {
|
||||
select: {
|
||||
createdAt: true,
|
||||
description: true,
|
||||
discordCategory: true,
|
||||
emoji: true,
|
||||
id: true,
|
||||
image: true,
|
||||
name: true,
|
||||
requiredRoles: true,
|
||||
staffRoles: true,
|
||||
tickets: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: { id: req.params.guild },
|
||||
});
|
||||
|
||||
// include: {
|
||||
// questions: {
|
||||
// select: {
|
||||
// createdAt: true,
|
||||
// id: true,
|
||||
// label: true,
|
||||
// maxLength: true,
|
||||
// minLength: true,
|
||||
// order: true,
|
||||
// placeholder: true,
|
||||
// required: true,
|
||||
// style: true,
|
||||
// value: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
categories = categories.map(c => {
|
||||
c = {
|
||||
...c,
|
||||
stats: {
|
||||
avgResolutionTime: ms(c.tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / c.tickets.length),
|
||||
avgResponseTime: ms(c.tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / c.tickets.length),
|
||||
},
|
||||
};
|
||||
delete c.tickets;
|
||||
return c;
|
||||
});
|
||||
|
||||
return categories;
|
||||
},
|
||||
|
@ -34,6 +34,7 @@ module.exports.get = fastify => ({
|
||||
logo: guild.iconURL(),
|
||||
name: guild.name,
|
||||
stats: {
|
||||
avgResolutionTime: ms(tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
||||
avgResponseTime: ms(tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
||||
categories: categories.map(c => ({
|
||||
id: c.id,
|
||||
|
@ -23,6 +23,7 @@ module.exports.get = () => ({
|
||||
stats: {
|
||||
activatedUsers: users.length,
|
||||
archivedMessages: users.reduce((total, user) => total + user.messageCount, 0), // don't count archivedMessage table rows, they get deleted
|
||||
avgResolutionTime: ms(tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
||||
avgResponseTime: ms(tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
||||
categories: await client.prisma.category.count(),
|
||||
guilds: client.guilds.cache.size,
|
||||
@ -32,7 +33,7 @@ module.exports.get = () => ({
|
||||
},
|
||||
username: client.user.username,
|
||||
};
|
||||
await client.keyv.set(cacheKey, cached, ms('5m'));
|
||||
await client.keyv.set(cacheKey, cached, ms('15m'));
|
||||
}
|
||||
|
||||
return cached;
|
||||
|
Loading…
Reference in New Issue
Block a user