aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/videos/channel-syncs-command.ts
blob: de4a160ec13ac2fff6b6abbf5c6cc3a98108082e (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
import { HttpStatusCode, ResultList, VideoChannelSync, VideoChannelSyncCreate } from '@shared/models'
import { pick } from '@shared/core-utils'
import { unwrapBody } from '../requests'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class ChannelSyncsCommand extends AbstractCommand {
  private static readonly API_PATH = '/api/v1/video-channel-syncs'

  listByAccount (options: OverrideCommandOptions & {
    accountName: string
    start?: number
    count?: number
    sort?: string
  }) {
    const { accountName, sort = 'createdAt' } = options

    const path = `/api/v1/accounts/${accountName}/video-channel-syncs`

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

      path,
      query: { sort, ...pick(options, [ 'start', 'count' ]) },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  async create (options: OverrideCommandOptions & {
    attributes: VideoChannelSyncCreate
  }) {
    return unwrapBody<{ videoChannelSync: VideoChannelSync }>(this.postBodyRequest({
      ...options,

      path: ChannelSyncsCommand.API_PATH,
      fields: options.attributes,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    }))
  }

  delete (options: OverrideCommandOptions & {
    channelSyncId: number
  }) {
    const path = `${ChannelSyncsCommand.API_PATH}/${options.channelSyncId}`

    return this.deleteRequest({
      ...options,

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