|
@@ -1,7 +1,7 @@
|
|
|
/*
|
|
|
eslint-disable @typescript-eslint/naming-convention
|
|
|
*/
|
|
|
-import { EventContext, StoreContext } from '@joystream/hydra-common'
|
|
|
+import { DatabaseManager, EventContext, StoreContext } from '@joystream/hydra-common'
|
|
|
import { Storage } from '../generated/types/storage'
|
|
|
import {
|
|
|
DistributionBucket,
|
|
@@ -411,6 +411,15 @@ export async function storage_DistributionBucketDeleted({ event, store }: EventC
|
|
|
return store.save<StorageBag>(bag)
|
|
|
})
|
|
|
)
|
|
|
+
|
|
|
+ // Remove invited bucket operators
|
|
|
+ const invitedOperators = await store.getMany(DistributionBucketOperator, {
|
|
|
+ where: {
|
|
|
+ status: DistributionBucketOperatorStatus.INVITED,
|
|
|
+ distributionBucket,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ await Promise.all(invitedOperators.map((operator) => removeDistributionBucketOperator(store, operator)))
|
|
|
await store.remove<DistributionBucket>(distributionBucket)
|
|
|
}
|
|
|
|
|
@@ -509,8 +518,11 @@ export async function storage_DistributionBucketOperatorRemoved({
|
|
|
const [bucketId, workerId] = new Storage.DistributionBucketOperatorRemovedEvent(event).params
|
|
|
|
|
|
// TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
|
|
|
-
|
|
|
const operator = await getDistributionBucketOperatorWithMetadata(store, distributionOperatorId(bucketId, workerId))
|
|
|
+ await removeDistributionBucketOperator(store, operator)
|
|
|
+}
|
|
|
+
|
|
|
+async function removeDistributionBucketOperator(store: DatabaseManager, operator: DistributionBucketOperator) {
|
|
|
await store.remove<DistributionBucketOperator>(operator)
|
|
|
if (operator.metadata) {
|
|
|
await store.remove<DistributionBucketOperatorMetadata>(operator.metadata)
|