fix(artists): tolerate missing flash_items table to avoid 500s on artist fetch
This commit is contained in:
parent
cf5f775e0f
commit
41eca45e07
21
lib/db.ts
21
lib/db.ts
@ -164,12 +164,19 @@ export async function getArtistWithPortfolio(id: string, env?: any): Promise<imp
|
|||||||
ORDER BY order_index ASC, created_at DESC
|
ORDER BY order_index ASC, created_at DESC
|
||||||
`).bind(id).all();
|
`).bind(id).all();
|
||||||
|
|
||||||
// Fetch flash items (public only)
|
// Fetch flash items (public only) - tolerate missing table in older DBs
|
||||||
const flashResult = await db.prepare(`
|
let flashRows: any[] = []
|
||||||
SELECT * FROM flash_items
|
try {
|
||||||
WHERE artist_id = ? AND is_available = 1
|
const flashResult = await db.prepare(`
|
||||||
ORDER BY order_index ASC, created_at DESC
|
SELECT * FROM flash_items
|
||||||
`).bind(id).all();
|
WHERE artist_id = ? AND is_available = 1
|
||||||
|
ORDER BY order_index ASC, created_at DESC
|
||||||
|
`).bind(id).all();
|
||||||
|
flashRows = flashResult.results as any[]
|
||||||
|
} catch (_err) {
|
||||||
|
// Table may not exist yet; treat as empty
|
||||||
|
flashRows = []
|
||||||
|
}
|
||||||
|
|
||||||
const artist = artistResult as any;
|
const artist = artistResult as any;
|
||||||
|
|
||||||
@ -194,7 +201,7 @@ export async function getArtistWithPortfolio(id: string, env?: any): Promise<imp
|
|||||||
createdAt: new Date(img.created_at)
|
createdAt: new Date(img.created_at)
|
||||||
})),
|
})),
|
||||||
// Attach as non-breaking field (not in Artist type but useful to callers)
|
// Attach as non-breaking field (not in Artist type but useful to callers)
|
||||||
flashItems: (flashResult.results as any[]).map(row => ({
|
flashItems: flashRows.map(row => ({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
artistId: row.artist_id,
|
artistId: row.artist_id,
|
||||||
url: row.url,
|
url: row.url,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user