updateChannelCategory.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import { getInputJson } from '../../helpers/InputOutput'
  3. import { ChannelCategoryInputParameters } from '../../Types'
  4. import { asValidatedMetadata, metadataToBytes } from '../../helpers/serialization'
  5. import { CreateInterface } from '@joystream/types'
  6. import { ChannelCategoryUpdateParameters } from '@joystream/types/content'
  7. import { flags } from '@oclif/command'
  8. import { ChannelCategoryInputSchema } from '../../json-schemas/ContentDirectory'
  9. import { ChannelCategoryMetadata } from '@joystream/metadata-protobuf'
  10. export default class UpdateChannelCategoryCommand extends ContentDirectoryCommandBase {
  11. static description = 'Update channel category inside content directory.'
  12. static flags = {
  13. context: ContentDirectoryCommandBase.categoriesContextFlag,
  14. input: flags.string({
  15. char: 'i',
  16. required: true,
  17. description: `Path to JSON file to use as input`,
  18. }),
  19. }
  20. static args = [
  21. {
  22. name: 'channelCategoryId',
  23. required: true,
  24. description: 'ID of the Channel Category',
  25. },
  26. ]
  27. async run() {
  28. const { context, input } = this.parse(UpdateChannelCategoryCommand).flags
  29. const { channelCategoryId } = this.parse(UpdateChannelCategoryCommand).args
  30. const [actor, address] = context ? await this.getContentActor(context) : await this.getCategoryManagementActor()
  31. const channelCategoryInput = await getInputJson<ChannelCategoryInputParameters>(input, ChannelCategoryInputSchema)
  32. const meta = asValidatedMetadata(ChannelCategoryMetadata, channelCategoryInput)
  33. const channelCategoryUpdateParameters: CreateInterface<ChannelCategoryUpdateParameters> = {
  34. new_meta: metadataToBytes(ChannelCategoryMetadata, meta),
  35. }
  36. this.jsonPrettyPrint(JSON.stringify(channelCategoryInput))
  37. await this.requireConfirmation('Do you confirm the provided input?', true)
  38. await this.sendAndFollowNamedTx(await this.getDecodedPair(address), 'content', 'updateChannelCategory', [
  39. actor,
  40. channelCategoryId,
  41. channelCategoryUpdateParameters,
  42. ])
  43. }
  44. }