removeEntity.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import { Actor } from '@joystream/types/content-directory'
  3. import ExitCodes from '../../ExitCodes'
  4. export default class RemoveEntityCommand extends ContentDirectoryCommandBase {
  5. static description = 'Removes a single entity by id (can be executed in Member, Curator or Lead context)'
  6. static flags = {
  7. context: ContentDirectoryCommandBase.contextFlag,
  8. }
  9. static args = [
  10. {
  11. name: 'id',
  12. required: true,
  13. description: 'ID of the entity to remove',
  14. },
  15. ]
  16. async run() {
  17. let {
  18. args: { id },
  19. flags: { context },
  20. } = this.parse(RemoveEntityCommand)
  21. const entity = await this.getEntity(id, undefined, undefined, false)
  22. const [, entityClass] = await this.classEntryByNameOrId(entity.class_id.toString())
  23. if (!context) {
  24. context = await this.promptForContext()
  25. }
  26. const account = await this.getRequiredSelectedAccount()
  27. const actor: Actor = await this.getActor(context, entityClass)
  28. if (!actor.isOfType('Curator') && !this.isActorEntityController(actor, entity, false)) {
  29. this.error('You are not the entity controller!', { exit: ExitCodes.AccessDenied })
  30. }
  31. await this.requireConfirmation(
  32. `Are you sure you want to remove entity ${id} of class ${entityClass.name.toString()}?`
  33. )
  34. await this.requestAccountDecoding(account)
  35. await this.sendAndFollowNamedTx(account, 'contentDirectory', 'removeEntity', [actor, id])
  36. }
  37. }