aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/videos/change-ownership-command.ts
blob: ad4c726efa36f157df46334482ef3ff93148d5f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { HttpStatusCode, ResultList, VideoChangeOwnership } from '@shared/models'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class ChangeOwnershipCommand extends AbstractCommand {

  create (options: OverrideCommandOptions & {
    videoId: number | string
    username: string
  }) {
    const { videoId, username } = options
    const path = '/api/v1/videos/' + videoId + '/give-ownership'

    return this.postBodyRequest({
      ...options,

      path,
      fields: { username },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  list (options: OverrideCommandOptions = {}) {
    const path = '/api/v1/videos/ownership'

    return this.getRequestBody<ResultList<VideoChangeOwnership>>({
      ...options,

      path,
      query: { sort: '-createdAt' },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  accept (options: OverrideCommandOptions & {
    ownershipId: number
    channelId: number
  }) {
    const { ownershipId, channelId } = options
    const path = '/api/v1/videos/ownership/' + ownershipId + '/accept'

    return this.postBodyRequest({
      ...options,

      path,
      fields: { channelId },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  refuse (options: OverrideCommandOptions & {
    ownershipId: number
  }) {
    const { ownershipId } = options
    const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse'

    return this.postBodyRequest({
      ...options,

      path,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }
}