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 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;
},

View File

@ -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,

View File

@ -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;