Add ZXDB origins and label types

Show entry origins data and display label type names
in label detail view.

Signed-off-by: codex@lucy.xalior.com
This commit is contained in:
2026-01-10 18:12:30 +00:00
parent e2f6aac856
commit fb206734db
3 changed files with 125 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import {
searchByAliases,
searchByOrigins,
labels,
labeltypes,
authors,
publishers,
languages,
@@ -31,6 +32,7 @@ import {
licensors,
permissions,
permissiontypes,
origintypes,
webrefs,
websites,
magazines,
@@ -297,6 +299,14 @@ export interface EntryDetail {
linkSite?: string | null;
comments?: string | null;
}[];
origins?: {
type: { id: string; name: string | null };
libraryTitle: string;
publication: string | null;
containerId: number | null;
issueId: number | null;
date: { year: number | null; month: number | null; day: number | null };
}[];
// Additional entry fields for richer details
maxPlayers?: number;
availabletypeId?: string | null;
@@ -559,6 +569,17 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
linkSite: string | null;
comments: string | null;
}[] = [];
let originRows: {
libraryTitle: string;
origintypeId: string;
origintypeName: string | null;
containerId: number | string | null;
issueId: number | string | null;
dateYear: number | string | null;
dateMonth: number | string | null;
dateDay: number | string | null;
publication: string | null;
}[] = [];
try {
aliasRows = await db
.select({ releaseSeq: aliases.releaseSeq, languageId: aliases.languageId, title: aliases.title })
@@ -591,6 +612,24 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
.where(eq(relatedlicenses.entryId, id));
licenseRows = rows as typeof licenseRows;
} catch {}
try {
const rows = await db
.select({
libraryTitle: searchByOrigins.libraryTitle,
origintypeId: searchByOrigins.origintypeId,
origintypeName: origintypes.name,
containerId: searchByOrigins.containerId,
issueId: searchByOrigins.issueId,
dateYear: searchByOrigins.dateYear,
dateMonth: searchByOrigins.dateMonth,
dateDay: searchByOrigins.dateDay,
publication: searchByOrigins.publication,
})
.from(searchByOrigins)
.leftJoin(origintypes, eq(origintypes.id, searchByOrigins.origintypeId))
.where(eq(searchByOrigins.entryId, id));
originRows = rows as typeof originRows;
} catch {}
return {
id: base.id,
@@ -610,6 +649,18 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
linkSite: l.linkSite ?? null,
comments: l.comments ?? null,
})),
origins: originRows.map((o) => ({
type: { id: o.origintypeId, name: o.origintypeName ?? null },
libraryTitle: o.libraryTitle,
publication: o.publication ?? null,
containerId: o.containerId != null ? Number(o.containerId) : null,
issueId: o.issueId != null ? Number(o.issueId) : null,
date: {
year: o.dateYear != null ? Number(o.dateYear) : null,
month: o.dateMonth != null ? Number(o.dateMonth) : null,
day: o.dateDay != null ? Number(o.dateDay) : null,
},
})),
maxPlayers: (base.maxPlayers) ?? undefined,
availabletypeId: (base.availabletypeId) ?? undefined,
withoutLoadScreen: (base.withoutLoadScreen) ?? undefined,
@@ -651,6 +702,7 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
// ----- Labels -----
export interface LabelDetail extends LabelSummary {
labeltypeName: string | null;
permissions: {
website: { id: number; name: string; link?: string | null };
type: { id: string; name: string | null };
@@ -709,7 +761,17 @@ export async function searchLabels(params: LabelSearchParams): Promise<PagedResu
}
export async function getLabelById(id: number): Promise<LabelDetail | null> {
const rows = await db.select().from(labels).where(eq(labels.id, id)).limit(1);
const rows = await db
.select({
id: labels.id,
name: labels.name,
labeltypeId: labels.labeltypeId,
labeltypeName: labeltypes.name,
})
.from(labels)
.leftJoin(labeltypes, eq(labeltypes.id, labels.labeltypeId))
.where(eq(labels.id, id))
.limit(1);
const base = rows[0];
if (!base) return null;
@@ -770,6 +832,7 @@ export async function getLabelById(id: number): Promise<LabelDetail | null> {
id: base.id,
name: base.name,
labeltypeId: base.labeltypeId,
labeltypeName: base.labeltypeName ?? null,
permissions: permissionRows.map((p) => ({
website: { id: Number(p.websiteId), name: p.websiteName, link: p.websiteLink ?? null },
type: { id: p.permissiontypeId, name: p.permissiontypeName ?? null },