Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
26
app/api/options/repeater-choices/route.ts
Normal file
26
app/api/options/repeater-choices/route.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { directusFetch } from "@/lib/directus";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const target = searchParams.get("target") || "";
|
||||
const group = searchParams.get("group") || "";
|
||||
const field = searchParams.get("field") || "type";
|
||||
if (!target || !group) return NextResponse.json({ error: "missing target/group" }, { status: 400 });
|
||||
|
||||
const meta = await directusFetch<any>(`/fields/${target}/${group}?fields=meta`);
|
||||
const fields = meta?.data?.meta?.options?.fields ?? [];
|
||||
const nested = fields.find((f: any) => (f?.field ?? f?.key) === field);
|
||||
const choices = nested?.options?.choices ?? nested?.meta?.options?.choices ?? [];
|
||||
|
||||
const out = (choices as any[])
|
||||
.map((c) => ({
|
||||
id: String(c.value ?? c.text ?? c.label ?? ""),
|
||||
label: String(c.text ?? c.label ?? c.value ?? ""),
|
||||
}))
|
||||
.filter((o) => o.id)
|
||||
.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
return NextResponse.json({ data: out });
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue