Fixed date usage

This commit is contained in:
Joao Ramos
2024-08-20 09:17:48 +01:00
parent ba5d926659
commit 9db33e6a51

View File

@@ -112,6 +112,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const assigneesData = data.assignees const assigneesData = data.assignees
.map((assignee: string) => { .map((assignee: string) => {
const userStats = allStats.filter((s: any) => s.user === assignee); const userStats = allStats.filter((s: any) => s.user === assignee);
const dates = userStats.map((s: any) => moment(s.date));
return { return {
userId: assignee, userId: assignee,
user: users.find((u) => u.id === assignee), user: users.find((u) => u.id === assignee),
@@ -126,6 +127,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
}, },
{ correct: 0, missing: 0, total: 0 } { correct: 0, missing: 0, total: 0 }
), ),
firstDate: moment.min(...dates),
lastDate: moment.max(...dates),
stats: userStats, stats: userStats,
}; };
}) })
@@ -135,13 +138,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const highestScore = Math.max(...results); const highestScore = Math.max(...results);
const lowestScore = Math.min(...results); const lowestScore = Math.min(...results);
const averageScore = results.reduce((a, b) => a + b, 0) / results.length; const averageScore = results.reduce((a, b) => a + b, 0) / results.length;
const firstDate = moment.min(assigneesData.map((r: any) => r.firstDate));
const dates = assigneesData const lastDate = moment.max(assigneesData.map((r: any) => r.lastDate));
.flatMap((r: any) => r.stats)
.map((r: any) => r.date)
.map((d: number) => moment(d));
const firstDate = moment.min(dates);
const lastDate = moment.max(dates);
const firstSectionData = [ const firstSectionData = [
{ {