export const getById = zQuery({
args: { id: zid('videoCollection') },
handler: async (ctx, { id }) => {
// Get the collection
const collection = await ctx.db.get(id)
if (!collection) return null
// Get the videos from the collection videos
const videos = await Promise.all(collection.videos.map((videoId) => ctx.db.get(videoId))).then(
(results) => results.filter((r) => r !== null),
) // <- ISSUE: this currently returns null, even with the filter, because ctx.db.get() can return null
// Enrich the videos
const enrichedVideos = await Promise.all(videos.map(async (video) => enrichVideo(ctx, video)))
// Return the collection including the videos
return { title: collection.title, videos }
},
})
export const getById = zQuery({
args: { id: zid('videoCollection') },
handler: async (ctx, { id }) => {
// Get the collection
const collection = await ctx.db.get(id)
if (!collection) return null
// Get the videos from the collection videos
const videos = await Promise.all(collection.videos.map((videoId) => ctx.db.get(videoId))).then(
(results) => results.filter((r) => r !== null),
) // <- ISSUE: this currently returns null, even with the filter, because ctx.db.get() can return null
// Enrich the videos
const enrichedVideos = await Promise.all(videos.map(async (video) => enrichVideo(ctx, video)))
// Return the collection including the videos
return { title: collection.title, videos }
},
})