feat(capa): require note and photos via /submit, block PATCH bypass

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 11:10:03 +08:00
co-authored by Claude Sonnet 5.5
parent cf5719883c
commit 51986b7ae5
9 changed files with 275 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
export const MAX_CAPA_PHOTOS = 5
export type CapaSubmissionResult =
| { ok: true; note: string }
| { ok: false; errors: string[] }
export function validateCapaSubmission(
note: string,
files: ReadonlyArray<{ type: string }>,
): CapaSubmissionResult {
const errors: string[] = []
const trimmed = note.trim()
if (!trimmed) errors.push('Completion note is required')
if (files.length < 1) errors.push('At least 1 photo is required')
if (files.length > MAX_CAPA_PHOTOS) errors.push(`At most ${MAX_CAPA_PHOTOS} photos are allowed`)
if (files.some(f => !f.type.startsWith('image/'))) errors.push('Only image files are allowed')
return errors.length ? { ok: false, errors } : { ok: true, note: trimmed }
}
+2
View File
@@ -10,6 +10,7 @@ import {
date,
jsonb,
customType,
type AnyPgColumn,
} from 'drizzle-orm/pg-core'
// ---------------------------------------------------------------------------
@@ -145,6 +146,7 @@ export const evidenceFiles = pgTable('evidence_files', {
uploadedBy: uuid('uploaded_by').notNull().references(() => users.id),
uploadedAt: timestamp('uploaded_at', { withTimezone: true }).notNull().defaultNow(),
deleted: boolean('deleted').notNull().default(false),
capaId: uuid('capa_id').references((): AnyPgColumn => capaActions.id),
})
export const investigations = pgTable('investigations', {