]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/users/accounts-command.ts
Introduce accounts command
[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 },
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}