1 import { pick } from '@shared/core-utils'
2 import { HttpStatusCode, Job, JobState, JobType, ResultList } from '@shared/models'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 export class JobsCommand extends AbstractCommand {
7 async getLatest (options: OverrideCommandOptions & {
10 const { data } = await this.list({ ...options, start: 0, count: 1, sort: '-createdAt' })
12 if (data.length === 0) return undefined
17 list (options: OverrideCommandOptions & {
24 const path = this.buildJobsUrl(options.state)
26 const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ])
28 return this.getRequestBody<ResultList<Job>>({
34 defaultExpectedStatus: HttpStatusCode.OK_200
38 listFailed (options: OverrideCommandOptions & {
41 const path = this.buildJobsUrl('failed')
43 return this.getRequestBody<ResultList<Job>>({
47 query: { start: 0, count: 50 },
49 defaultExpectedStatus: HttpStatusCode.OK_200
53 private buildJobsUrl (state?: JobState) {
54 let path = '/api/v1/jobs'
56 if (state) path += '/' + state