]>
Commit | Line | Data |
---|---|---|
9fff08cf C |
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 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
21 | }) | |
22 | } | |
23 | ||
24 | get (options: OverrideCommandOptions & { | |
25 | accountName: string | |
26 | }) { | |
27 | const path = '/api/v1/accounts/' + options.accountName | |
28 | ||
29 | return this.getRequestBody<Account>({ | |
30 | ...options, | |
31 | ||
32 | path, | |
33 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
34 | }) | |
35 | } | |
36 | ||
37 | listRatings (options: OverrideCommandOptions & { | |
38 | accountName: string | |
39 | rating?: VideoRateType | |
40 | }) { | |
41 | const { rating, accountName } = options | |
42 | const path = '/api/v1/accounts/' + accountName + '/ratings' | |
43 | ||
44 | const query = { rating } | |
45 | ||
46 | return this.getRequestBody<ResultList<AccountVideoRate>>({ | |
47 | ...options, | |
48 | ||
49 | path, | |
50 | query, | |
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
52 | }) | |
53 | } | |
54 | } |