-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathbatch.ts
38 lines (34 loc) · 991 Bytes
/
batch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type {
Batch,
BatchesResults,
TasksOrBatchesQuery,
} from "./types/index.js";
import type { HttpRequests } from "./http-requests.js";
/**
* Class for handling batches.
*
* @see {@link https://www.meilisearch.com/docs/reference/api/batches}
*/
export class BatchClient {
readonly #httpRequest: HttpRequests;
constructor(httpRequests: HttpRequests) {
this.#httpRequest = httpRequests;
}
/** {@link https://www.meilisearch.com/docs/reference/api/batches#get-one-batch} */
async getBatch(uid: number): Promise<Batch> {
const batch = await this.#httpRequest.get<Batch>({
path: `batches/${uid}`,
});
return batch;
}
/** {@link https://www.meilisearch.com/docs/reference/api/batches#get-batches} */
async getBatches(
batchesQuery?: TasksOrBatchesQuery,
): Promise<BatchesResults> {
const batches = await this.#httpRequest.get<BatchesResults>({
path: "batches",
params: batchesQuery,
});
return batches;
}
}