Browse Source

query node - mappings logging III + unwrap() removal

ondratra 4 years ago
parent
commit
0040f626ed

+ 9 - 4
query-node/mappings/src/content/channel.ts

@@ -84,10 +84,13 @@ export async function content_ChannelUpdated(
     }
   }
 
+  // prepare changed reward account
+  const newRewardAccount = channelUpdateParameters.reward_account.isSome && channelUpdateParameters.reward_account.unwrapOr(null)
+
   // reward account change happened?
-  if (channelUpdateParameters.reward_account.isSome) {
+  if (newRewardAccount) {
     // this will change the `channel`!
-    handleChannelRewardAccountChange(channel, channelUpdateParameters.reward_account.unwrap()) // TODO: get rid of unwrap
+    handleChannelRewardAccountChange(channel, newRewardAccount)
   }
 
   // save channel
@@ -268,9 +271,11 @@ function handleChannelRewardAccountChange(
   channel: Channel, // will be modified inside of the function!
   reward_account: Option<AccountId>
 ) {
+  const rewardAccount = reward_account.isSome && reward_account.unwrapOr(null)
+
   // new different reward account set?
-  if (reward_account.isSome) {
-    channel.rewardAccount = reward_account.unwrap().toString() // TODO: get rid of unwrap
+  if (rewardAccount) {
+    channel.rewardAccount = rewardAccount.toString()
     return
   }
 

+ 4 - 4
query-node/mappings/src/content/curatorGroup.ts

@@ -27,7 +27,7 @@ export async function content_CuratorGroupCreated(
   await db.save<CuratorGroup>(curatorGroup)
 
   // emit log event
-  logger.info('Curator group has been created', {id: curatorGroupId.id})
+  logger.info('Curator group has been created', {id: curatorGroupId})
 }
 
 export async function content_CuratorGroupStatusSet(
@@ -52,7 +52,7 @@ export async function content_CuratorGroupStatusSet(
   await db.save<CuratorGroup>(curatorGroup)
 
   // emit log event
-  logger.info('Curator group status has been set', {id: curatorGroupId.id, isActive})
+  logger.info('Curator group status has been set', {id: curatorGroupId, isActive})
 }
 
 export async function content_CuratorAdded(
@@ -77,7 +77,7 @@ export async function content_CuratorAdded(
   await db.save<CuratorGroup>(curatorGroup)
 
   // emit log event
-  logger.info('Curator has been added to curator group', {id: curatorGroupId.id, curatorId})
+  logger.info('Curator has been added to curator group', {id: curatorGroupId, curatorId})
 }
 
 export async function content_CuratorRemoved(
@@ -109,5 +109,5 @@ export async function content_CuratorRemoved(
   await db.save<CuratorGroup>(curatorGroup)
 
   // emit log event
-  logger.info('Curator has been removed from curator group', {id: curatorGroupId.id, curatorId})
+  logger.info('Curator has been removed from curator group', {id: curatorGroupId, curatorId})
 }

+ 0 - 1
query-node/mappings/src/content/utils.ts

@@ -1,4 +1,3 @@
-// TODO: add logging of mapping events (entity found/not found, entity updated/deleted, etc.)
 // TODO: check all `db.get()` and similar calls recieve a proper type argument (aka add `.toString()`, etc. to those calls)
 // TODO: can we rely on db having "foreign keys"? When item is deleted will automaticly be all relations to it unset?
 //       Similarly, will saving item also save all its related items no-yet-saved in db, or do they need to saved individually?

+ 8 - 8
query-node/mappings/src/content/video.ts

@@ -49,7 +49,7 @@ export async function content_VideoCategoryCreated(
   await db.save<VideoCategory>(videoCategory)
 
   // emit log event
-  logger.info('Video category has been created', {id: videoCategoryId.id})
+  logger.info('Video category has been created', {id: videoCategoryId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -86,7 +86,7 @@ export async function content_VideoCategoryUpdated(
   await db.save<VideoCategory>(videoCategory)
 
   // emit log event
-  logger.info('Video category has been updated', {id: videoCategoryId.id})
+  logger.info('Video category has been updated', {id: videoCategoryId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -109,7 +109,7 @@ export async function content_VideoCategoryDeleted(
   await db.remove<VideoCategory>(videoCategory)
 
   // emit log event
-  logger.info('Video category has been deleted', {id: videoCategoryId.id})
+  logger.info('Video category has been deleted', {id: videoCategoryId})
 }
 
 /////////////////// Video //////////////////////////////////////////////////////
@@ -144,7 +144,7 @@ export async function content_VideoCreated(
   await db.save<Video>(video)
 
   // emit log event
-  logger.info('Video has been created', {id: videoId.id})
+  logger.info('Video has been created', {id: videoId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -196,7 +196,7 @@ export async function content_VideoUpdated(
   await db.save<Video>(video)
 
   // emit log event
-  logger.info('Video has been updated', {id: videoId.id})
+  logger.info('Video has been updated', {id: videoId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -219,7 +219,7 @@ export async function content_VideoDeleted(
   await db.remove<Video>(video)
 
   // emit log event
-  logger.info('Video has been deleted', {id: videoId.id})
+  logger.info('Video has been deleted', {id: videoId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -245,7 +245,7 @@ export async function content_VideoCensored(
   await db.save<Video>(video)
 
   // emit log event
-  logger.info('Video has been censored', {id: videoId.id})
+  logger.info('Video has been censored', {id: videoId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -271,7 +271,7 @@ export async function content_VideoUncensored(
   await db.save<Video>(video)
 
   // emit log event
-  logger.info('Video has been uncensored', {id: videoId.id})
+  logger.info('Video has been uncensored', {id: videoId})
 }
 
 // eslint-disable-next-line @typescript-eslint/naming-convention