备注功能
This commit is contained in:
@@ -2,10 +2,11 @@ import { NextRequest } from 'next/server'
|
||||
import { prisma } from '@/src/lib/prisma'
|
||||
import { isAuthorizedDelete } from '@/src/lib/utils'
|
||||
|
||||
export async function GET(_req: NextRequest, { params }: { params: { id: string } }) {
|
||||
export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
try {
|
||||
const rec = await prisma.recording.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
timestamp: true,
|
||||
@@ -46,12 +47,13 @@ export async function GET(_req: NextRequest, { params }: { params: { id: string
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest, { params }: { params: { id: string } }) {
|
||||
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
try {
|
||||
if (!isAuthorizedDelete(req)) {
|
||||
return Response.json({ error: 'unauthorized' }, { status: 401 })
|
||||
}
|
||||
const rec = await prisma.recording.delete({ where: { id: params.id } })
|
||||
const rec = await prisma.recording.delete({ where: { id } })
|
||||
return Response.json({ success: true, id: rec.id })
|
||||
} catch (err: any) {
|
||||
if (err?.code === 'P2025') {
|
||||
@@ -61,3 +63,29 @@ export async function DELETE(req: NextRequest, { params }: { params: { id: strin
|
||||
return Response.json({ error: 'internal error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
try {
|
||||
const body = await req.json()
|
||||
const { note } = body
|
||||
|
||||
if (note !== undefined && typeof note !== 'string') {
|
||||
return Response.json({ error: 'invalid note' }, { status: 400 })
|
||||
}
|
||||
|
||||
const rec = await prisma.recording.update({
|
||||
where: { id },
|
||||
data: { note: note || null },
|
||||
select: { id: true, note: true },
|
||||
})
|
||||
|
||||
return Response.json({ success: true, id: rec.id, note: rec.note })
|
||||
} catch (err: any) {
|
||||
if (err?.code === 'P2025') {
|
||||
return Response.json({ error: 'not found' }, { status: 404 })
|
||||
}
|
||||
console.error(err)
|
||||
return Response.json({ error: 'internal error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ export async function GET(req: NextRequest) {
|
||||
force_min: true,
|
||||
force_max: true,
|
||||
force_avg: true,
|
||||
note: true,
|
||||
},
|
||||
}),
|
||||
])
|
||||
@@ -65,6 +66,7 @@ export async function GET(req: NextRequest) {
|
||||
duration: r.duration,
|
||||
hasFit: r.fit_a !== null && r.fit_a !== undefined,
|
||||
fit: r.fit_a !== null && r.fit_a !== undefined ? { a: r.fit_a!, b: r.fit_b! } : undefined,
|
||||
note: r.note ?? undefined,
|
||||
stats: {
|
||||
codeMin: r.code_min,
|
||||
codeMax: r.code_max,
|
||||
|
||||
Reference in New Issue
Block a user