]>
Commit | Line | Data |
---|---|---|
1 | import { ResultList } from '@shared/models' | |
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | |
3 | import { Account } from '../../models/actors' | |
4 | import { AccountVideoRate, VideoRateType } from '../../models/videos' | |
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | |
6 | ||
7 | export 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 }, | |
20 | implicitToken: false, | |
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, | |
34 | implicitToken: false, | |
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, | |
53 | implicitToken: true, | |
54 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
55 | }) | |
56 | } | |
57 | } |