]>
Commit | Line | Data |
---|---|---|
b033851f | 1 | import { pick } from '@shared/core-utils' |
c0e8b12e | 2 | import { HttpStatusCode } from '@shared/models' |
9c6327f8 C |
3 | import { Job, JobState, JobType, ResultList } from '../../models' |
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | |
5 | ||
6 | export class JobsCommand extends AbstractCommand { | |
7 | ||
0305db28 JB |
8 | async getLatest (options: OverrideCommandOptions & { |
9 | jobType: JobType | |
10 | }) { | |
851675c5 | 11 | const { data } = await this.list({ ...options, start: 0, count: 1, sort: '-createdAt' }) |
0305db28 JB |
12 | |
13 | if (data.length === 0) return undefined | |
14 | ||
15 | return data[0] | |
16 | } | |
17 | ||
851675c5 | 18 | list (options: OverrideCommandOptions & { |
9c6327f8 C |
19 | state?: JobState |
20 | jobType?: JobType | |
21 | start?: number | |
22 | count?: number | |
23 | sort?: string | |
24 | } = {}) { | |
25 | const path = this.buildJobsUrl(options.state) | |
26 | ||
27 | const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ]) | |
28 | ||
29 | return this.getRequestBody<ResultList<Job>>({ | |
30 | ...options, | |
31 | ||
32 | path, | |
33 | query, | |
a1637fa1 | 34 | implicitToken: true, |
9c6327f8 C |
35 | defaultExpectedStatus: HttpStatusCode.OK_200 |
36 | }) | |
37 | } | |
38 | ||
39 | private buildJobsUrl (state?: JobState) { | |
40 | let path = '/api/v1/jobs' | |
41 | ||
42 | if (state) path += '/' + state | |
43 | ||
44 | return path | |
45 | } | |
46 | } |