aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/accounts-command.ts
blob: 89c080e93316f6e2a361fab7029ae8b8d61a7153 (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
import { ResultList } from '@shared/models'
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { Account } from '../../models/actors'
import { AccountVideoRate, VideoRateType } from '../../models/videos'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class AccountsCommand extends AbstractCommand {

  list (options: OverrideCommandOptions & {
    sort?: string // default -createdAt
  } = {}) {
    const { sort = '-createdAt' } = options
    const path = '/api/v1/accounts'

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

      path,
      query: { sort },
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  get (options: OverrideCommandOptions & {
    accountName: string
  }) {
    const path = '/api/v1/accounts/' + options.accountName

    return this.getRequestBody<Account>({
      ...options,

      path,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  listRatings (options: OverrideCommandOptions & {
    accountName: string
    rating?: VideoRateType
  }) {
    const { rating, accountName } = options
    const path = '/api/v1/accounts/' + accountName + '/ratings'

    const query = { rating }

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

      path,
      query,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }
}