This commit is contained in:
Isaac 2022-08-05 14:01:19 +01:00
parent 954681685a
commit cdb8fa04c4
No known key found for this signature in database
GPG Key ID: F4EAABEB0FFCC06A
3 changed files with 32 additions and 19 deletions

View File

@ -1,33 +1,44 @@
const { logAdminEvent } = require('../../../../../../lib/logging'); const { logAdminEvent } = require('../../../../../../lib/logging');
const emoji = require('node-emoji'); const emoji = require('node-emoji');
const { ChannelType: { GuildCategory } } = require('discord.js'); const { ChannelType: { GuildCategory } } = require('discord.js');
const ms = require('ms');
module.exports.get = fastify => ({ module.exports.get = fastify => ({
handler: async (req, res) => { handler: async (req, res) => {
/** @type {import('client')} */ /** @type {import('client')} */
const client = res.context.config.client; const client = res.context.config.client;
const { categories } = await client.prisma.guild.findUnique({ let { categories } = await client.prisma.guild.findUnique({
select: { categories: true }, 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 }, where: { id: req.params.guild },
}); });
// include: { categories = categories.map(c => {
// questions: { c = {
// select: { ...c,
// createdAt: true, stats: {
// id: true, avgResolutionTime: ms(c.tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / c.tickets.length),
// label: true, avgResponseTime: ms(c.tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / c.tickets.length),
// maxLength: true, },
// minLength: true, };
// order: true, delete c.tickets;
// placeholder: true, return c;
// required: true, });
// style: true,
// value: true,
// },
// },
// },
return categories; return categories;
}, },

View File

@ -34,6 +34,7 @@ module.exports.get = fastify => ({
logo: guild.iconURL(), logo: guild.iconURL(),
name: guild.name, name: guild.name,
stats: { 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), avgResponseTime: ms(tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / tickets.length),
categories: categories.map(c => ({ categories: categories.map(c => ({
id: c.id, id: c.id,

View File

@ -23,6 +23,7 @@ module.exports.get = () => ({
stats: { stats: {
activatedUsers: users.length, activatedUsers: users.length,
archivedMessages: users.reduce((total, user) => total + user.messageCount, 0), // don't count archivedMessage table rows, they get deleted 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), avgResponseTime: ms(tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / tickets.length),
categories: await client.prisma.category.count(), categories: await client.prisma.category.count(),
guilds: client.guilds.cache.size, guilds: client.guilds.cache.size,
@ -32,7 +33,7 @@ module.exports.get = () => ({
}, },
username: client.user.username, username: client.user.username,
}; };
await client.keyv.set(cacheKey, cached, ms('5m')); await client.keyv.set(cacheKey, cached, ms('15m'));
} }
return cached; return cached;