diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /shared/extra-utils/users/accounts-command.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'shared/extra-utils/users/accounts-command.ts')
-rw-r--r-- | shared/extra-utils/users/accounts-command.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/shared/extra-utils/users/accounts-command.ts b/shared/extra-utils/users/accounts-command.ts new file mode 100644 index 000000000..2f586104e --- /dev/null +++ b/shared/extra-utils/users/accounts-command.ts | |||
@@ -0,0 +1,56 @@ | |||
1 | import { HttpStatusCode, ResultList } from '@shared/models' | ||
2 | import { Account } from '../../models/actors' | ||
3 | import { AccountVideoRate, VideoRateType } from '../../models/videos' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class AccountsCommand extends AbstractCommand { | ||
7 | |||
8 | list (options: OverrideCommandOptions & { | ||
9 | sort?: string // default -createdAt | ||
10 | } = {}) { | ||
11 | const { sort = '-createdAt' } = options | ||
12 | const path = '/api/v1/accounts' | ||
13 | |||
14 | return this.getRequestBody<ResultList<Account>>({ | ||
15 | ...options, | ||
16 | |||
17 | path, | ||
18 | query: { sort }, | ||
19 | implicitToken: false, | ||
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 | implicitToken: false, | ||
34 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | listRatings (options: OverrideCommandOptions & { | ||
39 | accountName: string | ||
40 | rating?: VideoRateType | ||
41 | }) { | ||
42 | const { rating, accountName } = options | ||
43 | const path = '/api/v1/accounts/' + accountName + '/ratings' | ||
44 | |||
45 | const query = { rating } | ||
46 | |||
47 | return this.getRequestBody<ResultList<AccountVideoRate>>({ | ||
48 | ...options, | ||
49 | |||
50 | path, | ||
51 | query, | ||
52 | implicitToken: true, | ||
53 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
54 | }) | ||
55 | } | ||
56 | } | ||