1
0
Fork 0
peertube/shared/extra-utils/users/accounts-command.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-16 08:27:30 -04:00
import { HttpStatusCode, ResultList } from '@shared/models'
2021-07-07 07:38:26 -04:00
import { Account } from '../../models/actors'
import { AccountVideoRate, VideoRateType } from '../../models/videos'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class AccountsCommand extends AbstractCommand {
list (options: OverrideCommandOptions & {
sort?: string // default -createdAt
} = {}) {
const { sort = '-createdAt' } = options
const path = '/api/v1/accounts'
return this.getRequestBody<ResultList<Account>>({
...options,
path,
query: { sort },
implicitToken: false,
2021-07-07 07:38:26 -04:00
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
get (options: OverrideCommandOptions & {
accountName: string
}) {
const path = '/api/v1/accounts/' + options.accountName
return this.getRequestBody<Account>({
...options,
path,
implicitToken: false,
2021-07-07 07:38:26 -04:00
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
listRatings (options: OverrideCommandOptions & {
accountName: string
rating?: VideoRateType
}) {
const { rating, accountName } = options
const path = '/api/v1/accounts/' + accountName + '/ratings'
const query = { rating }
return this.getRequestBody<ResultList<AccountVideoRate>>({
...options,
path,
query,
implicitToken: true,
2021-07-07 07:38:26 -04:00
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}