]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/users/accounts-command.ts
Specify if we want to fallback to the server token
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / accounts-command.ts
CommitLineData
9fff08cf
C
1import { ResultList } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { Account } from '../../models/actors'
4import { AccountVideoRate, VideoRateType } from '../../models/videos'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class AccountsCommand extends AbstractCommand {
8
9 list (options: OverrideCommandOptions & {
10 sort?: string // default -createdAt
11 } = {}) {
12 const { sort = '-createdAt' } = options
13 const path = '/api/v1/accounts'
14
15 return this.getRequestBody<ResultList<Account>>({
16 ...options,
17
18 path,
19 query: { sort },
a1637fa1 20 implicitToken: false,
9fff08cf
C
21 defaultExpectedStatus: HttpStatusCode.OK_200
22 })
23 }
24
25 get (options: OverrideCommandOptions & {
26 accountName: string
27 }) {
28 const path = '/api/v1/accounts/' + options.accountName
29
30 return this.getRequestBody<Account>({
31 ...options,
32
33 path,
a1637fa1 34 implicitToken: false,
9fff08cf
C
35 defaultExpectedStatus: HttpStatusCode.OK_200
36 })
37 }
38
39 listRatings (options: OverrideCommandOptions & {
40 accountName: string
41 rating?: VideoRateType
42 }) {
43 const { rating, accountName } = options
44 const path = '/api/v1/accounts/' + accountName + '/ratings'
45
46 const query = { rating }
47
48 return this.getRequestBody<ResultList<AccountVideoRate>>({
49 ...options,
50
51 path,
52 query,
a1637fa1 53 implicitToken: true,
9fff08cf
C
54 defaultExpectedStatus: HttpStatusCode.OK_200
55 })
56 }
57}