]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/jobs-command.ts
Shorter live methods
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / jobs-command.ts
CommitLineData
9c6327f8
C
1import { pick } from 'lodash'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { Job, JobState, JobType, ResultList } from '../../models'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class JobsCommand extends AbstractCommand {
7
8 getJobsList (options: OverrideCommandOptions & {
9 state?: JobState
10 jobType?: JobType
11 start?: number
12 count?: number
13 sort?: string
14 } = {}) {
15 const path = this.buildJobsUrl(options.state)
16
17 const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ])
18
19 return this.getRequestBody<ResultList<Job>>({
20 ...options,
21
22 path,
23 query,
24 defaultExpectedStatus: HttpStatusCode.OK_200
25 })
26 }
27
28 private buildJobsUrl (state?: JobState) {
29 let path = '/api/v1/jobs'
30
31 if (state) path += '/' + state
32
33 return path
34 }
35}