fix: align report schedule route context types

This commit is contained in:
Esdras Renan 2025-11-10 02:37:17 -03:00
parent 127e117ea9
commit d859c1196c

View file

@ -12,14 +12,17 @@ import {
export const runtime = "nodejs" export const runtime = "nodejs"
export async function PATCH(request: Request, { params }: { params: { id: string } }) { type RouteContext = { params: Promise<{ id: string }> }
export async function PATCH(request: Request, context: RouteContext) {
const { id } = await context.params
const session = await assertAdminSession() const session = await assertAdminSession()
if (!session) { if (!session) {
return NextResponse.json({ error: "Não autorizado" }, { status: 401 }) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
} }
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
const schedule = await prisma.reportExportSchedule.findFirst({ const schedule = await prisma.reportExportSchedule.findFirst({
where: { id: params.id, tenantId }, where: { id, tenantId },
}) })
if (!schedule) { if (!schedule) {
return NextResponse.json({ error: "Agendamento não encontrado" }, { status: 404 }) return NextResponse.json({ error: "Agendamento não encontrado" }, { status: 404 })
@ -140,14 +143,15 @@ export async function PATCH(request: Request, { params }: { params: { id: string
}) })
} }
export async function DELETE(_: Request, { params }: { params: { id: string } }) { export async function DELETE(_: Request, context: RouteContext) {
const { id } = await context.params
const session = await assertAdminSession() const session = await assertAdminSession()
if (!session) { if (!session) {
return NextResponse.json({ error: "Não autorizado" }, { status: 401 }) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
} }
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
await prisma.reportExportRun.deleteMany({ where: { scheduleId: params.id, tenantId } }) await prisma.reportExportRun.deleteMany({ where: { scheduleId: id, tenantId } })
await prisma.reportExportSchedule.deleteMany({ where: { id: params.id, tenantId } }) await prisma.reportExportSchedule.deleteMany({ where: { id, tenantId } })
return NextResponse.json({ success: true }) return NextResponse.json({ success: true })
} }