mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-05-05 03:04:52 +00:00
code: package,nextjs,frontends (2 files)
This commit is contained in:
@@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user