Fix entries's video retrieval

This commit is contained in:
Zoe Roux 2025-03-09 16:50:20 +01:00
parent d61573668b
commit 34926dab51
No known key found for this signature in database
2 changed files with 9 additions and 3 deletions

View File

@ -41,6 +41,7 @@ import {
sortToSql, sortToSql,
} from "~/models/utils"; } from "~/models/utils";
import { desc } from "~/models/utils/descriptions"; import { desc } from "~/models/utils/descriptions";
import type { EmbeddedVideo } from "~/models/video";
const entryFilters: FilterDef = { const entryFilters: FilterDef = {
kind: { kind: {
@ -115,9 +116,14 @@ async function getEntries({
const videosQ = db const videosQ = db
.select({ .select({
videos: coalesce( videos: coalesce(
jsonbAgg(jsonbBuildObject({ slug: entryVideoJoin.slug, ...videosCol })), jsonbAgg(
jsonbBuildObject<EmbeddedVideo>({
slug: entryVideoJoin.slug,
...videosCol,
}),
),
sql`'[]'::jsonb`, sql`'[]'::jsonb`,
), ).as("videos"),
}) })
.from(entryVideoJoin) .from(entryVideoJoin)
.where(eq(entryVideoJoin.entryPk, entries.pk)) .where(eq(entryVideoJoin.entryPk, entries.pk))

View File

@ -73,7 +73,7 @@ export const Video = t.Intersect([Resource(), SeedVideo, DbMetadata]);
export type Video = Prettify<typeof Video.static>; export type Video = Prettify<typeof Video.static>;
// type used in entry responses // type used in entry responses
export const EmbeddedVideo = t.Omit(Video, ["createdAt", "updatedAt"]); export const EmbeddedVideo = t.Omit(Video, ["guess", "createdAt", "updatedAt"]);
export type EmbeddedVideo = Prettify<typeof EmbeddedVideo.static>; export type EmbeddedVideo = Prettify<typeof EmbeddedVideo.static>;
registerExamples(Video, bubbleVideo); registerExamples(Video, bubbleVideo);