|
@@ -1,8 +1,8 @@
|
|
|
/*
|
|
|
eslint-disable @typescript-eslint/naming-convention
|
|
|
*/
|
|
|
-import { EventContext, StoreContext } from '@joystream/hydra-common'
|
|
|
-import { Storage } from '../../generated/types/storage'
|
|
|
+import { DatabaseManager, EventContext, StoreContext } from '@joystream/hydra-common'
|
|
|
+import { Storage } from '../generated/types/storage'
|
|
|
import {
|
|
|
DistributionBucket,
|
|
|
DistributionBucketFamily,
|
|
@@ -410,6 +410,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)
|
|
|
}
|
|
|
|
|
@@ -508,8 +517,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)
|