Hastic standalone
https://hastic.io
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
977 B
32 lines
977 B
3 years ago
|
import { API_URL } from "@/config";
|
||
|
import { Segment, SegmentId } from "@/types/segment";
|
||
|
import axios from 'axios';
|
||
|
|
||
|
import _ from 'lodash';
|
||
|
|
||
|
const SEGMENTS_API_URL = API_URL + "segments/";
|
||
|
|
||
3 years ago
|
export async function getSegments(from: number, to: number): Promise<Segment[]> {
|
||
3 years ago
|
if(from >= to) {
|
||
|
throw new Error("`from` can`t be less than `to`");
|
||
|
}
|
||
|
|
||
|
const uri = SEGMENTS_API_URL + `?from=${from}&to=${to}`;
|
||
|
const res = await axios.get(uri);
|
||
|
|
||
3 years ago
|
return res["data"] as Segment[];
|
||
3 years ago
|
}
|
||
|
|
||
|
export async function postSegment(segment: Segment): Promise<SegmentId> {
|
||
3 years ago
|
const segObj = segment.toObject();
|
||
|
segObj.id = undefined; // because we post a new segment. It's a hack
|
||
|
|
||
|
const resp = await axios.post(SEGMENTS_API_URL, segObj);
|
||
3 years ago
|
return resp['data']['id'];
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
export async function deleteSegment(from: number, to: number): Promise<SegmentId> {
|
||
|
const uri = SEGMENTS_API_URL + `?from=${from}&to=${to}`;
|
||
|
const resp = await axios.delete(uri);
|
||
|
return resp['data']['count'];
|
||
|
}
|