Browse Source

Merge branch 'working-groups-mappings-fixes' into olympia-staging

Leszek Wiesner 3 years ago
parent
commit
834d71ed73

+ 9 - 2
query-node/mappings/workingGroups.ts

@@ -71,6 +71,7 @@ import {
   BudgetSetEvent,
   BudgetSpendingEvent,
   LeaderSetEvent,
+  WorkerStatusLeaving,
 } from 'query-node/dist/model'
 import { createType } from '@joystream/types'
 
@@ -794,9 +795,15 @@ export async function workingGroups_WorkerExited({ store, event }: EventContext
   })
 
   await store.save<WorkerExitedEvent>(workerExitedEvent)
-  ;(worker.status as WorkerStatusLeft).workerExitedEventId = workerExitedEvent.id
+
+  const newStatus = new WorkerStatusLeft()
+  newStatus.workerStartedLeavingEventId = (worker.status as WorkerStatusLeaving).workerStartedLeavingEventId
+  newStatus.workerExitedEventId = workerExitedEvent.id
+
+  worker.status = newStatus
   worker.stake = new BN(0)
   worker.rewardPerBlock = new BN(0)
+  worker.missingRewardAmount = undefined
   worker.updatedAt = eventTime
 
   await store.save<Worker>(worker)
@@ -910,7 +917,7 @@ export async function workingGroups_WorkerStartedLeaving({ store, event }: Event
 
   await store.save<WorkerStartedLeavingEvent>(workerStartedLeavingEvent)
 
-  const status = new WorkerStatusLeft()
+  const status = new WorkerStatusLeaving()
   status.workerStartedLeavingEventId = workerStartedLeavingEvent.id
   worker.status = status
   worker.updatedAt = eventTime

+ 8 - 3
query-node/schemas/workingGroups.graphql

@@ -3,12 +3,17 @@ type WorkerStatusActive @variant {
   _phantom: Int
 }
 
+type WorkerStatusLeaving @variant {
+  "Related event emitted on leaving initialization"
+  workerStartedLeavingEvent: WorkerStartedLeavingEvent!
+}
+
 type WorkerStatusLeft @variant {
   "Related event emitted on leaving initialization"
   workerStartedLeavingEvent: WorkerStartedLeavingEvent!
 
-  "Related event emitted (and set) when the unstaking period is finished"
-  workerExitedEvent: WorkerExitedEvent
+  "Related event emitted once the worker has exited the role (after the unstaking period)"
+  workerExitedEvent: WorkerExitedEvent!
 }
 
 type WorkerStatusTerminated @variant {
@@ -16,7 +21,7 @@ type WorkerStatusTerminated @variant {
   terminatedWorkerEvent: TerminatedWorkerEvent!
 }
 
-union WorkerStatus = WorkerStatusActive | WorkerStatusLeft | WorkerStatusTerminated
+union WorkerStatus = WorkerStatusActive | WorkerStatusLeaving | WorkerStatusLeft | WorkerStatusTerminated
 
 # Working Groups
 type Worker @entity {

+ 1 - 1
tests/integration-tests/src/fixtures/workingGroups/LeaveRoleFixture.ts

@@ -56,7 +56,7 @@ export class LeaveRoleFixture extends BaseWorkingGroupFixture {
       const worker = qWorkers.find((w) => w.runtimeId === workerId.toNumber())
       Utils.assert(worker, 'Query node: Worker not found!')
       Utils.assert(
-        worker.status.__typename === 'WorkerStatusLeft',
+        worker.status.__typename === 'WorkerStatusLeaving',
         `Invalid worker status: ${worker.status.__typename}`
       )
       Utils.assert(worker.status.workerStartedLeavingEvent, 'Query node: Missing workerStartedLeavingEvent relation')

+ 6 - 0
tests/integration-tests/src/graphql/generated/queries.ts

@@ -1201,6 +1201,7 @@ export type WorkerFieldsFragment = {
   membership: { id: string }
   status:
     | { __typename: 'WorkerStatusActive' }
+    | { __typename: 'WorkerStatusLeaving'; workerStartedLeavingEvent?: Types.Maybe<{ id: string }> }
     | {
         __typename: 'WorkerStatusLeft'
         workerStartedLeavingEvent?: Types.Maybe<{ id: string }>
@@ -2908,6 +2909,11 @@ export const WorkerFields = gql`
     stakeAccount
     status {
       __typename
+      ... on WorkerStatusLeaving {
+        workerStartedLeavingEvent {
+          id
+        }
+      }
       ... on WorkerStatusLeft {
         workerStartedLeavingEvent {
           id

+ 7 - 2
tests/integration-tests/src/graphql/generated/schema.ts

@@ -16267,7 +16267,7 @@ export type WorkerStartedLeavingEventWhereUniqueInput = {
   id: Scalars['ID']
 }
 
-export type WorkerStatus = WorkerStatusActive | WorkerStatusLeft | WorkerStatusTerminated
+export type WorkerStatus = WorkerStatusActive | WorkerStatusLeaving | WorkerStatusLeft | WorkerStatusTerminated
 
 export type WorkerStatusActive = {
   phantom?: Maybe<Scalars['Int']>
@@ -16320,10 +16320,15 @@ export type WorkerStatusActiveWhereUniqueInput = {
   id: Scalars['ID']
 }
 
+export type WorkerStatusLeaving = {
+  /** Related event emitted on leaving initialization */
+  workerStartedLeavingEvent?: Maybe<WorkerStartedLeavingEvent>
+}
+
 export type WorkerStatusLeft = {
   /** Related event emitted on leaving initialization */
   workerStartedLeavingEvent?: Maybe<WorkerStartedLeavingEvent>
-  /** Related event emitted (and set) when the unstaking period is finished */
+  /** Related event emitted once the worker has exited the role (after the unstaking period) */
   workerExitedEvent?: Maybe<WorkerExitedEvent>
 }
 

+ 5 - 0
tests/integration-tests/src/graphql/queries/workingGroups.graphql

@@ -71,6 +71,11 @@ fragment WorkerFields on Worker {
   stakeAccount
   status {
     __typename
+    ... on WorkerStatusLeaving {
+      workerStartedLeavingEvent {
+        id
+      }
+    }
     ... on WorkerStatusLeft {
       workerStartedLeavingEvent {
         id

+ 3 - 3
yarn.lock

@@ -7588,9 +7588,9 @@ aws-credstash@^3.0.0:
     debug "^4.3.1"
 
 aws-sdk@^2.567.0:
-  version "2.925.0"
-  resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.925.0.tgz#a352f3adc8274120fb31fa4fc04527d44b6107cf"
-  integrity sha512-dHXngzuSTZvIFWizWbU+ceZTAKmgodzEIi/AWbB+z0THKfxD3Iz/CJ7kZ7a9QyZv7X082L68vv3siMhXBMoTLA==
+  version "2.926.0"
+  resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.926.0.tgz#96f40b3e8400957becc5b8446e2322c0ff0e8a85"
+  integrity sha512-GFdAznnwxBxRPUTLP8gyFG8GhbUQ0sWwNCocYHkS/FB18hr8gmB3xv2m7VVWA/YkPDXvviPnoB680Z47VSEkqA==
   dependencies:
     buffer "4.9.2"
     events "1.1.1"