Scrum4Me/lib/idea-dto.ts
Scrum4Me Agent 4a929b1962 feat(ideas): secondary_products meeladen in IdeaDto en alle queries
Voegt IdeaProduct schema toe (dependency van story-qtkvz6ly), breidt
IdeaWithProduct type en IdeaDto interface uit met secondary_products array,
en laadt de relatie mee in findMany/findFirst in page.tsx en REST GET.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 02:20:34 +02:00

52 lines
1.8 KiB
TypeScript

// API-projection voor Idea — converteert Prisma-row naar het externe contract.
// Belangrijk: status wordt naar lowercase API-string vertaald (zelfde patroon
// als TaskStatus / StoryStatus / PbiStatus elders in de codebase).
import { ideaStatusToApi } from '@/lib/idea-status'
import type { Idea, IdeaStatus, Product } from '@prisma/client'
type IdeaWithProduct = Idea & {
product: Pick<Product, 'id' | 'name' | 'repo_url'> | null
pbi?: { id: string; code: string; title: string } | null
secondary_products?: { id: string; product_id: string; product: { id: string; name: string } }[]
}
export interface IdeaDto {
id: string
code: string
title: string
description: string | null
status: ReturnType<typeof ideaStatusToApi>
product_id: string | null
product: { id: string; name: string; repo_url: string | null } | null
pbi_id: string | null
pbi?: { id: string; code: string; title: string } | null
secondary_products: { id: string; product_id: string; product: { id: string; name: string } }[]
archived: boolean
has_grill_md: boolean
has_plan_md: boolean
created_at: string
updated_at: string
}
export function ideaToDto(idea: IdeaWithProduct & { status: IdeaStatus }): IdeaDto {
return {
id: idea.id,
code: idea.code,
title: idea.title,
description: idea.description,
status: ideaStatusToApi(idea.status),
product_id: idea.product_id,
product: idea.product,
pbi_id: idea.pbi_id,
pbi: idea.pbi ?? null,
secondary_products: idea.secondary_products ?? [],
archived: idea.archived,
// Geen md-content in lijst-payloads (kan groot zijn) — enkel een vlag.
has_grill_md: idea.grill_md !== null,
has_plan_md: idea.plan_md !== null,
created_at: idea.created_at.toISOString(),
updated_at: idea.updated_at.toISOString(),
}
}