code: package,nextjs,frontends (2 files)

This commit is contained in:
2025-12-26 00:22:32 +00:00
parent 784591cdf0
commit 76e7176ab9
2 changed files with 60 additions and 0 deletions
@@ -0,0 +1,25 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { getPackageData } from '@/lib/db/packages/get-package-data'
interface RouteParams {
params: {
packageId: string
}
}
export async function GET(_request: NextRequest, { params }: RouteParams) {
try {
const data = await getPackageData(params.packageId)
return NextResponse.json({ data })
} catch (error) {
console.error('Error fetching package data:', error)
return NextResponse.json(
{
error: 'Failed to fetch package data',
details: error instanceof Error ? error.message : 'Unknown error',
},
{ status: 500 }
)
}
}
@@ -0,0 +1,35 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { readJson } from '@/lib/api/read-json'
import { setPackageData } from '@/lib/db/packages/set-package-data'
type PackageDataPayload = {
data?: Record<string, any[]>
}
interface RouteParams {
params: {
packageId: string
}
}
export async function PUT(request: NextRequest, { params }: RouteParams) {
try {
const body = await readJson<PackageDataPayload>(request)
if (!body || !body.data || Array.isArray(body.data)) {
return NextResponse.json({ error: 'Package data is required' }, { status: 400 })
}
await setPackageData(params.packageId, body.data)
return NextResponse.json({ saved: true })
} catch (error) {
console.error('Error saving package data:', error)
return NextResponse.json(
{
error: 'Failed to save package data',
details: error instanceof Error ? error.message : 'Unknown error',
},
{ status: 500 }
)
}
}