aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/accounts-command.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/users/accounts-command.ts')
-rw-r--r--shared/extra-utils/users/accounts-command.ts54
1 files changed, 54 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..89c080e93
--- /dev/null
+++ b/shared/extra-utils/users/accounts-command.ts
@@ -0,0 +1,54 @@
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 },
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}