-
Notifications
You must be signed in to change notification settings - Fork 3
/
LocationManager.ts
45 lines (41 loc) · 1.37 KB
/
LocationManager.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
39
40
41
42
43
44
45
import fetch from 'node-fetch';
import { Manager } from '../Manager';
import { getApiURL } from '../Util';
import { LocationOptions, ILocation, Response } from '../Interfaces';
import { Locations } from './Locations';
export class LocationManager extends Manager {
/**
* Get locations.
* @param options Options to pass to the API.
*/
async get(options?: LocationOptions): Promise<Locations[]> {
const parsedOptions = { limit: 50, ...(options || {}) };
const res = await fetch(getApiURL(this.snipeURL, '/locations', parsedOptions), {
method: 'GET',
headers: {
Authorization: `Bearer ${this.apiToken}`,
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
const result = await res.json();
const json: Response<ILocation> = result;
return json.rows.map((location) => new Locations(location));
}
/**
* Fetch specific status label.
* @param id ID of status label to fetch.
*/
// async getID(id: number) {
// const res = await fetch(getApiURL(this.snipeURL, `/statuslabels/${id}`), {
// method: "GET",
// headers: {
// "Authorization": `Bearer ${this.apiToken}`,
// "Accept": "application/json",
// "Content-Type": "application/json"
// } });
// const result = await res.json();
// const json: IStatusLabel = result;
// return new StatusLabel(json);
// }
}