Adds in dashboard page showing basic Mantis statistics

This commit is contained in:
Cameron Redmore 2025-04-26 09:32:59 +01:00
parent 7564937faa
commit 92230f8a07
13 changed files with 595 additions and 19 deletions

View file

@ -3,6 +3,7 @@ import { PrismaClient } from '@prisma/client'; // Import Prisma Client
import { getMantisSettings, saveTicketToDatabase } from '../services/mantisDownloader.js';
import axios from 'axios';
import reader from '@kenjiuno/msgreader';
import SuperJSON from 'superjson';
const MsgReader = reader.default;
const prisma = new PrismaClient(); // Instantiate Prisma Client
@ -281,4 +282,78 @@ router.get('/msg-extract/:ticketId/:attachmentId/:innerAttachmentId', async(req,
}
});
// GET /mantis/stats/issues - Get daily count of new Mantis issues (last 7 days)
router.get('/stats/issues', async(req, res) =>
{
try
{
// Calculate the date range (last 7 days)
const endDate = new Date();
endDate.setHours(23, 59, 59, 999); // End of today
const startDate = new Date();
startDate.setDate(startDate.getDate() - 6); // 7 days ago
startDate.setHours(0, 0, 0, 0); // Start of the day
// Query for daily counts of issues created in the last 7 days
const dailyIssues = await prisma.$queryRaw`
SELECT
DATE(created_at) as date,
COUNT(*) as count
FROM
"MantisIssue"
WHERE
created_at >= ${startDate} AND created_at <= ${endDate}
GROUP BY
DATE(created_at)
ORDER BY
date ASC
`;
res.status(200).json(dailyIssues);
}
catch (error)
{
console.error('Error fetching Mantis issue statistics:', error.message);
res.status(500).json({ error: 'Failed to fetch Mantis issue statistics' });
}
});
// GET /mantis/stats/comments - Get daily count of new Mantis comments (last 7 days)
router.get('/stats/comments', async(req, res) =>
{
try
{
// Calculate the date range (last 7 days)
const endDate = new Date();
endDate.setHours(23, 59, 59, 999); // End of today
const startDate = new Date();
startDate.setDate(startDate.getDate() - 6); // 7 days ago
startDate.setHours(0, 0, 0, 0); // Start of the day
// Query for daily counts of comments created in the last 7 days
const dailyComments = await prisma.$queryRaw`
SELECT
DATE(created_at) as date,
COUNT(*) as count
FROM
"MantisComment"
WHERE
created_at >= ${startDate} AND created_at <= ${endDate}
GROUP BY
DATE(created_at)
ORDER BY
date ASC
`;
res.status(200).json(dailyComments);
}
catch (error)
{
console.error('Error fetching Mantis comment statistics:', error.message);
res.status(500).json({ error: 'Failed to fetch Mantis comment statistics' });
}
});
export default router;