feat(ST-513): accept optional metadata in story log and switch validation errors to 422
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bec0f4adc8
commit
2ce47ce68e
4 changed files with 15 additions and 6 deletions
|
|
@ -27,11 +27,11 @@ export async function POST(request: Request) {
|
|||
}
|
||||
|
||||
if (!ALLOWED_TYPES.has(file.type)) {
|
||||
return Response.json({ error: 'Alleen JPEG, PNG en WebP zijn toegestaan' }, { status: 400 })
|
||||
return Response.json({ error: 'Alleen JPEG, PNG en WebP zijn toegestaan' }, { status: 422 })
|
||||
}
|
||||
|
||||
if (file.size > MAX_BYTES) {
|
||||
return Response.json({ error: 'Bestand is groter dan 12 MB' }, { status: 400 })
|
||||
return Response.json({ error: 'Bestand is groter dan 12 MB' }, { status: 422 })
|
||||
}
|
||||
|
||||
const input = Buffer.from(await file.arrayBuffer())
|
||||
|
|
|
|||
|
|
@ -1,23 +1,29 @@
|
|||
import { authenticateApiRequest } from '@/lib/api-auth'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { productAccessFilter } from '@/lib/product-access'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { z } from 'zod'
|
||||
|
||||
const metadataField = z.record(z.string(), z.unknown()).optional()
|
||||
|
||||
const logSchema = z.discriminatedUnion('type', [
|
||||
z.object({
|
||||
type: z.literal('IMPLEMENTATION_PLAN'),
|
||||
content: z.string().min(1),
|
||||
metadata: metadataField,
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('TEST_RESULT'),
|
||||
content: z.string().min(1),
|
||||
status: z.enum(['PASSED', 'FAILED']),
|
||||
metadata: metadataField,
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('COMMIT'),
|
||||
content: z.string().min(1),
|
||||
commit_hash: z.string().min(1),
|
||||
commit_message: z.string().min(1),
|
||||
metadata: metadataField,
|
||||
}),
|
||||
])
|
||||
|
||||
|
|
@ -45,7 +51,7 @@ export async function POST(
|
|||
const body = await request.json().catch(() => null)
|
||||
const parsed = logSchema.safeParse(body)
|
||||
if (!parsed.success) {
|
||||
return Response.json({ error: parsed.error.flatten() }, { status: 400 })
|
||||
return Response.json({ error: parsed.error.flatten() }, { status: 422 })
|
||||
}
|
||||
|
||||
const log = await prisma.storyLog.create({
|
||||
|
|
@ -56,6 +62,9 @@ export async function POST(
|
|||
status: 'status' in parsed.data ? parsed.data.status : null,
|
||||
commit_hash: 'commit_hash' in parsed.data ? parsed.data.commit_hash : null,
|
||||
commit_message: 'commit_message' in parsed.data ? parsed.data.commit_message : null,
|
||||
metadata: parsed.data.metadata
|
||||
? (parsed.data.metadata as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export async function PATCH(
|
|||
const body = await request.json().catch(() => null)
|
||||
const parsed = bodySchema.safeParse(body)
|
||||
if (!parsed.success) {
|
||||
return Response.json({ error: parsed.error.flatten() }, { status: 400 })
|
||||
return Response.json({ error: parsed.error.flatten() }, { status: 422 })
|
||||
}
|
||||
|
||||
const story = await prisma.story.findFirst({
|
||||
|
|
@ -38,7 +38,7 @@ export async function PATCH(
|
|||
const storyTaskIds = new Set(story.tasks.map(t => t.id))
|
||||
const invalidId = parsed.data.task_ids.find(id => !storyTaskIds.has(id))
|
||||
if (invalidId) {
|
||||
return Response.json({ error: `Ongeldig task_id: ${invalidId}` }, { status: 400 })
|
||||
return Response.json({ error: `Ongeldig task_id: ${invalidId}` }, { status: 422 })
|
||||
}
|
||||
|
||||
await prisma.$transaction(
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export async function POST(request: Request) {
|
|||
const body = await request.json().catch(() => null)
|
||||
const parsed = bodySchema.safeParse(body)
|
||||
if (!parsed.success) {
|
||||
return Response.json({ error: parsed.error.flatten() }, { status: 400 })
|
||||
return Response.json({ error: parsed.error.flatten() }, { status: 422 })
|
||||
}
|
||||
|
||||
const product = await prisma.product.findFirst({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue