change-ownership-command.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { HttpStatusCode, ResultList, VideoChangeOwnership } from '@shared/models'
  2. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  3. export class ChangeOwnershipCommand extends AbstractCommand {
  4. create (options: OverrideCommandOptions & {
  5. videoId: number | string
  6. username: string
  7. }) {
  8. const { videoId, username } = options
  9. const path = '/api/v1/videos/' + videoId + '/give-ownership'
  10. return this.postBodyRequest({
  11. ...options,
  12. path,
  13. fields: { username },
  14. implicitToken: true,
  15. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  16. })
  17. }
  18. list (options: OverrideCommandOptions = {}) {
  19. const path = '/api/v1/videos/ownership'
  20. return this.getRequestBody<ResultList<VideoChangeOwnership>>({
  21. ...options,
  22. path,
  23. query: { sort: '-createdAt' },
  24. implicitToken: true,
  25. defaultExpectedStatus: HttpStatusCode.OK_200
  26. })
  27. }
  28. accept (options: OverrideCommandOptions & {
  29. ownershipId: number
  30. channelId: number
  31. }) {
  32. const { ownershipId, channelId } = options
  33. const path = '/api/v1/videos/ownership/' + ownershipId + '/accept'
  34. return this.postBodyRequest({
  35. ...options,
  36. path,
  37. fields: { channelId },
  38. implicitToken: true,
  39. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  40. })
  41. }
  42. refuse (options: OverrideCommandOptions & {
  43. ownershipId: number
  44. }) {
  45. const { ownershipId } = options
  46. const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse'
  47. return this.postBodyRequest({
  48. ...options,
  49. path,
  50. implicitToken: true,
  51. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  52. })
  53. }
  54. }