Skip to content

Commit

Permalink
fix: debts export
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonprod committed Dec 19, 2023
1 parent 000142d commit 689454c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/api/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,23 @@ export async function GET(request: NextRequest) {
"Задолженности",
])

students?.forEach(async (student) => {
const promises = students!.map(async (student) => {
const debts = await getDebtsByStudent(student.id, supabase)
debts?.forEach((debt) => {
sheet.addRow([student.id, debt.name])
})
sheet.addRow([
student.id,
student.academic_group,
student.last_name,
student.first_name,
student.second_name,
student.personal_number,
student.institute,
debts,
])
})

// Wait for all promises to resolve before continuing
await Promise.all(promises)

const buffer = await workbook.xlsx.writeBuffer()
const today = new Date().toISOString().slice(0, 10)

Expand Down Expand Up @@ -75,5 +85,5 @@ async function getDebtsByStudent(
.from("debts_disciplines")
.select("name")
.eq("student_uuid", student_id)
return debts
return debts?.map((debt) => debt.name).join(",")
}

0 comments on commit 689454c

Please sign in to comment.