mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-07 18:41:26 +03:00
fix: response & resolution time stats
This commit is contained in:
@@ -406,9 +406,17 @@ module.exports = class TicketManager {
|
||||
const statsCacheKey = `cache/category-stats/${categoryId}`;
|
||||
let stats = await this.client.keyv.get(statsCacheKey);
|
||||
if (!stats) {
|
||||
const { tickets } = await this.client.prisma.category.findUnique({
|
||||
select: { tickets: { where: { open: false } } },
|
||||
where: { id: categoryId },
|
||||
const tickets = await this.client.prisma.ticket.findMany({
|
||||
select: {
|
||||
closedAt: true,
|
||||
createdAt: true,
|
||||
firstResponseAt: true,
|
||||
},
|
||||
where: {
|
||||
categoryId: category.id,
|
||||
firstResponseAt: { not: null },
|
||||
open: false,
|
||||
},
|
||||
});
|
||||
stats = {
|
||||
avgResolutionTime: ms(tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
||||
|
Reference in New Issue
Block a user