Add entry_id relationship links to Entries
- Introduce reusable EntryLink component - Use EntryLink in Releases and Label detail tables - Link both ID and title to /zxdb/entries/[id] for consistency Signed-off-by: Junie@MacOS
This commit is contained in:
@@ -20,6 +20,9 @@ import {
|
||||
availabletypes,
|
||||
currencies,
|
||||
roletypes,
|
||||
aliases,
|
||||
webrefs,
|
||||
websites,
|
||||
} from "@/server/schema/zxdb";
|
||||
|
||||
export interface SearchParams {
|
||||
@@ -219,6 +222,9 @@ export interface EntryDetail {
|
||||
year: number | null;
|
||||
}[];
|
||||
}[];
|
||||
// Additional relationships surfaced on the entry detail page
|
||||
aliases?: { releaseSeq: number; languageId: string; title: string }[];
|
||||
webrefs?: { link: string; languageId: string; website: { id: number; name: string; link?: string | null } }[];
|
||||
}
|
||||
|
||||
export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
@@ -411,6 +417,24 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
// Sort releases by sequence for stable UI order
|
||||
releasesData.sort((a, b) => a.releaseSeq - b.releaseSeq);
|
||||
|
||||
// Fetch extra relationships in parallel
|
||||
let aliasRows: { releaseSeq: number | string; languageId: string; title: string }[] = [];
|
||||
let webrefRows: { link: string; languageId: string; websiteId: number | string; websiteName: string; websiteLink: string | null }[] = [];
|
||||
try {
|
||||
aliasRows = await db
|
||||
.select({ releaseSeq: aliases.releaseSeq, languageId: aliases.languageId, title: aliases.title })
|
||||
.from(aliases)
|
||||
.where(eq(aliases.entryId, id));
|
||||
} catch {}
|
||||
try {
|
||||
const rows = await db
|
||||
.select({ link: webrefs.link, languageId: webrefs.languageId, websiteId: websites.id, websiteName: websites.name, websiteLink: websites.link })
|
||||
.from(webrefs)
|
||||
.innerJoin(websites, eq(websites.id, webrefs.websiteId))
|
||||
.where(eq(webrefs.entryId, id));
|
||||
webrefRows = rows as typeof webrefRows;
|
||||
} catch {}
|
||||
|
||||
return {
|
||||
id: base.id,
|
||||
title: base.title,
|
||||
@@ -453,6 +477,8 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
year: d.year != null ? Number(d.year) : null,
|
||||
releaseSeq: Number(d.releaseSeq),
|
||||
})),
|
||||
aliases: aliasRows.map((a) => ({ releaseSeq: Number(a.releaseSeq), languageId: a.languageId, title: a.title })),
|
||||
webrefs: webrefRows.map((w) => ({ link: w.link, languageId: w.languageId, website: { id: Number(w.websiteId), name: w.websiteName, link: w.websiteLink } })),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user