fix: use Next RouteContext helpers for dynamic API routes
This commit is contained in:
parent
d859c1196c
commit
a7921ffffb
3 changed files with 16 additions and 14 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import type { NextRequest } from "next/server"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { assertAdminSession } from "@/lib/auth-server"
|
||||
|
|
@ -12,10 +13,10 @@ import {
|
|||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
type RouteContext = { params: Promise<{ id: string }> }
|
||||
type Ctx = RouteContext<"/api/reports/schedules/[id]">
|
||||
|
||||
export async function PATCH(request: Request, context: RouteContext) {
|
||||
const { id } = await context.params
|
||||
export async function PATCH(request: NextRequest, ctx: Ctx) {
|
||||
const { id } = await ctx.params
|
||||
const session = await assertAdminSession()
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
|
|
@ -143,8 +144,8 @@ export async function PATCH(request: Request, context: RouteContext) {
|
|||
})
|
||||
}
|
||||
|
||||
export async function DELETE(_: Request, context: RouteContext) {
|
||||
const { id } = await context.params
|
||||
export async function DELETE(_: NextRequest, ctx: Ctx) {
|
||||
const { id } = await ctx.params
|
||||
const session = await assertAdminSession()
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import type { NextRequest } from "next/server"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { assertAdminSession } from "@/lib/auth-server"
|
||||
|
|
@ -6,14 +7,17 @@ import { prisma } from "@/lib/prisma"
|
|||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
export async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
type Ctx = RouteContext<"/api/reports/schedules/runs/[id]">
|
||||
|
||||
export async function GET(request: NextRequest, ctx: Ctx) {
|
||||
const { id } = await ctx.params
|
||||
const session = await assertAdminSession()
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
}
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
const run = await prisma.reportExportRun.findFirst({
|
||||
where: { id: params.id, tenantId },
|
||||
where: { id, tenantId },
|
||||
})
|
||||
if (!run || !run.artifacts) {
|
||||
return NextResponse.json({ error: "Arquivo não encontrado" }, { status: 404 })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue