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 { ConvexHttpClient } from "convex/browser"
|
||||
|
||||
|
|
@ -10,18 +11,14 @@ import { buildMachinesInventoryWorkbook, type MachineInventoryRecord } from "@/s
|
|||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{
|
||||
id: string
|
||||
}>
|
||||
}
|
||||
type Ctx = RouteContext<"/api/admin/devices/[id]/inventory.xlsx">
|
||||
|
||||
function sanitizeFilename(hostname: string, fallback: string): string {
|
||||
const safe = hostname.replace(/[^a-z0-9_-]/gi, "-").replace(/-{2,}/g, "-").toLowerCase()
|
||||
return safe || fallback
|
||||
}
|
||||
|
||||
export async function GET(_request: Request, context: RouteContext) {
|
||||
export async function GET(request: NextRequest, ctx: Ctx) {
|
||||
const session = await assertAuthenticatedSession()
|
||||
if (!session) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
|
||||
|
|
@ -30,7 +27,7 @@ export async function GET(_request: Request, context: RouteContext) {
|
|||
return NextResponse.json({ error: "Convex não configurado" }, { status: 500 })
|
||||
}
|
||||
|
||||
const { id } = await context.params
|
||||
const { id } = await ctx.params
|
||||
const machineId = id as Id<"machines">
|
||||
const client = new ConvexHttpClient(convexUrl)
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
|
|
|||
|
|
@ -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