|
|
@@ -3,7 +3,7 @@ import { getServerSession } from 'next-auth'
|
|
|
import { authOptions } from '@/lib/auth'
|
|
|
import { db } from '@/lib/db'
|
|
|
import { studentEnrollments, users, classes, sections, periods } from '@/lib/db/schema'
|
|
|
-import { eq, and, count } from 'drizzle-orm'
|
|
|
+import { eq, and } from 'drizzle-orm'
|
|
|
|
|
|
export async function GET(request: NextRequest) {
|
|
|
try {
|
|
|
@@ -21,7 +21,7 @@ export async function GET(request: NextRequest) {
|
|
|
const periodId = searchParams.get('periodId')
|
|
|
|
|
|
// Build the where conditions
|
|
|
- let whereConditions: any[] = []
|
|
|
+ const whereConditions = []
|
|
|
if (!includeInactive) {
|
|
|
whereConditions.push(eq(studentEnrollments.isActive, true))
|
|
|
}
|
|
|
@@ -30,7 +30,7 @@ export async function GET(request: NextRequest) {
|
|
|
}
|
|
|
|
|
|
// Get student enrollments with student, class, section, and period information
|
|
|
- let query = db
|
|
|
+ const baseQuery = db
|
|
|
.select({
|
|
|
id: studentEnrollments.id,
|
|
|
studentId: studentEnrollments.studentId,
|
|
|
@@ -54,9 +54,9 @@ export async function GET(request: NextRequest) {
|
|
|
.innerJoin(sections, eq(studentEnrollments.sectionId, sections.id))
|
|
|
.innerJoin(periods, eq(classes.periodId, periods.id))
|
|
|
|
|
|
- if (whereConditions.length > 0) {
|
|
|
- query = query.where(and(...whereConditions)) as any
|
|
|
- }
|
|
|
+ const query = whereConditions.length > 0
|
|
|
+ ? baseQuery.where(and(...whereConditions))
|
|
|
+ : baseQuery
|
|
|
|
|
|
const result = await query.orderBy(studentEnrollments.createdAt)
|
|
|
|