fix: resolve TypeScript build errors from leftJoin nullable types
Some checks failed
Build and Push Backend Image / build (push) Successful in 42s
Build and Push Frontend Image / build (push) Has been cancelled

Non-null assert photo/achievement ids that are structurally non-null
due to FK constraints but nullable in Drizzle's leftJoin return type.
Add missing description field to enrichVideo model select and map.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 19:33:16 +01:00
parent a558449964
commit 90497e9e7c
4 changed files with 24 additions and 6 deletions

View File

@@ -102,7 +102,14 @@ builder.queryField("userGamification", (t) =>
return { return {
stats: stats[0] ? { ...stats[0], rank } : null, stats: stats[0] ? { ...stats[0], rank } : null,
achievements: userAchievements.map((a) => ({ achievements: userAchievements.map((a) => ({
...a, id: a.id!,
code: a.code!,
name: a.name!,
description: a.description!,
icon: a.icon!,
category: a.category!,
required_count: a.required_count!,
progress: a.progress!,
date_unlocked: a.date_unlocked!, date_unlocked: a.date_unlocked!,
})), })),
recent_points: recentPoints, recent_points: recentPoints,

View File

@@ -15,8 +15,8 @@ async function enrichModel(db: DB, user: typeof users.$inferSelect) {
const seen = new Set<string>(); const seen = new Set<string>();
const photos = photoRows const photos = photoRows
.filter((p) => p.id && !seen.has(p.id) && seen.add(p.id)) .filter((p) => p.id !== null && !seen.has(p.id!) && seen.add(p.id!))
.map((p) => ({ id: p.id, filename: p.filename })); .map((p) => ({ id: p.id!, filename: p.filename! }));
return { ...user, photos }; return { ...user, photos };
} }

View File

@@ -195,8 +195,8 @@ builder.queryField("adminGetUser", (t) =>
.orderBy(user_photos.sort); .orderBy(user_photos.sort);
const seen = new Set<string>(); const seen = new Set<string>();
const photos = photoRows const photos = photoRows
.filter((p) => p.id && !seen.has(p.id) && seen.add(p.id)) .filter((p) => p.id !== null && !seen.has(p.id!) && seen.add(p.id!))
.map((p) => ({ id: p.id, filename: p.filename })); .map((p) => ({ id: p.id!, filename: p.filename! }));
return { ...user[0], photos }; return { ...user[0], photos };
}, },
}), }),

View File

@@ -41,6 +41,7 @@ async function enrichVideo(db: DB, video: typeof videos.$inferSelect) {
artist_name: users.artist_name, artist_name: users.artist_name,
slug: users.slug, slug: users.slug,
avatar: users.avatar, avatar: users.avatar,
description: users.description,
}) })
.from(video_models) .from(video_models)
.leftJoin(users, eq(video_models.user_id, users.id)) .leftJoin(users, eq(video_models.user_id, users.id))
@@ -63,9 +64,19 @@ async function enrichVideo(db: DB, video: typeof videos.$inferSelect) {
.from(video_plays) .from(video_plays)
.where(eq(video_plays.video_id, video.id)); .where(eq(video_plays.video_id, video.id));
const models = modelRows
.filter((m) => m.id !== null)
.map((m) => ({
id: m.id!,
artist_name: m.artist_name,
slug: m.slug,
avatar: m.avatar,
description: m.description,
}));
return { return {
...video, ...video,
models: modelRows, models,
movie_file: movieFile, movie_file: movieFile,
likes_count: likesCount[0]?.count || 0, likes_count: likesCount[0]?.count || 0,
plays_count: playsCount[0]?.count || 0, plays_count: playsCount[0]?.count || 0,