Browse Source

query node - license edit fix

ondratra 3 years ago
parent
commit
2550362c28
1 changed files with 10 additions and 2 deletions
  1. 10 2
      query-node/mappings/src/content/video.ts

+ 10 - 2
query-node/mappings/src/content/video.ts

@@ -242,6 +242,9 @@ export async function content_VideoUpdated(
   // prepare changed metadata
   const newMetadata = videoUpdateParameters.new_meta.unwrapOr(null)
 
+  // license must be deleted AFTER video is saved - plan a license deletion by assigning it to this variable
+  let licenseToDelete: License | null = null
+
   // update metadata if it was changed
   if (newMetadata) {
     const protobufContent = await readProtobufWithAssets(
@@ -266,9 +269,9 @@ export async function content_VideoUpdated(
       video[key] = value
     }
 
-    // license has changed - delete old license
+    // license has changed - plan old license delete
     if (originalLicense && video.license != originalLicense) {
-      await db.remove<License>(originalLicense)
+      licenseToDelete = originalLicense
     }
   }
 
@@ -278,6 +281,11 @@ export async function content_VideoUpdated(
   // save video
   await db.save<Video>(video)
 
+  // delete old license if it's planned
+  if (licenseToDelete) {
+    await db.remove<License>(licenseToDelete)
+  }
+
   // emit log event
   logger.info('Video has been updated', {id: videoId})
 }