Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/StudentAnalyticsDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { formatDateToISO } from "@/lib/utils";
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
import { format } from "date-fns";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -64,7 +65,8 @@ export const StudentAnalyticsDrawer = ({ studentId, courseId }: Props) => {
useEffect(() => {
const fetchQuestions = async () => {
if (!studentId) return;
const data = await getQuestionsAndResponsesForDate(courseId, studentId, selectedDate);
const formattedDate = formatDateToISO(selectedDate);
const data = await getQuestionsAndResponsesForDate(courseId, studentId, formattedDate);
setQuestionsForDate(data);
};
void fetchQuestions();
Expand Down
10 changes: 7 additions & 3 deletions services/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ export async function getStudentAnalytics(courseId: number, userId: string) {
export async function getQuestionsAndResponsesForDate(
courseId: number,
studentId: string,
date: Date,
isoDate: string,

) {
const start = new Date(isoDate)
const end = new Date(start)
end.setUTCHours(23, 59, 59, 999)
try {
const sessions = await prisma.courseSession.findMany({
where: {
courseId,
startTime: {
gte: new Date(date.setHours(0, 0, 0, 0)),
lt: new Date(date.setHours(23, 59, 59, 999)),
gte: start,
lt: end,
},
},
include: {
Expand Down