Selaa lähdekoodia

query-node: fetch relations explicitly for FeaturedVideo queries

metmirr 4 vuotta sitten
vanhempi
commit
b6b35bfeb3

+ 4 - 3
query-node/mappings/content-directory/entity/create.ts

@@ -403,18 +403,19 @@ async function createFeaturedVideo(
   nextEntityIdBeforeTransaction: number
 ): Promise<void> {
   const featuredVideo = new FeaturedVideo()
-  featuredVideo.id = id
+
   featuredVideo.video = await getOrCreate.video(
     { db, block, id },
     classEntityMap,
     p.video!,
     nextEntityIdBeforeTransaction
   )
-  featuredVideo.version = block
 
+  featuredVideo.id = id
+  featuredVideo.version = block
   featuredVideo.video.isFeatured = true
-  await db.save<Video>(featuredVideo.video)
 
+  await db.save<Video>(featuredVideo.video)
   await db.save<FeaturedVideo>(featuredVideo)
 }
 

+ 1 - 1
query-node/mappings/content-directory/entity/remove.ts

@@ -136,7 +136,7 @@ async function removeVideoMediaEncoding(db: DB, where: IWhereCond): Promise<void
 }
 
 async function removeFeaturedVideo(db: DB, where: IWhereCond): Promise<void> {
-  const record = await db.get(FeaturedVideo, where)
+  const record = await db.get(FeaturedVideo, { ...where, relations: ['video'] })
   if (!record) throw Error(`FeaturedVideo not found. id: ${where.where.id}`)
 
   record.video.isFeatured = false

+ 5 - 1
query-node/mappings/content-directory/entity/update.ts

@@ -290,7 +290,7 @@ async function updateFeaturedVideoEntityPropertyValues(
   props: IFeaturedVideo,
   entityIdBeforeTransaction: number
 ): Promise<void> {
-  const record = await db.get(FeaturedVideo, where)
+  const record = await db.get(FeaturedVideo, { ...where, relations: ['video'] })
   if (record === undefined) throw Error(`FeaturedVideo entity not found: ${where.where.id}`)
 
   if (props.video) {
@@ -298,6 +298,10 @@ async function updateFeaturedVideoEntityPropertyValues(
     const video = await db.get(Video, { where: { id } })
     if (!video) throw Error(`Video entity not found: ${id}`)
 
+    // Update old video isFeatured to false
+    record.video.isFeatured = false
+    await db.save<Video>(record.video)
+
     video.isFeatured = true
     record.video = video