blob: faedb48f2cd945ae416e69cc3489291eb62d9214 (
plain) (
blame)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
import { api_base } from "$lib/configuration";
import { is_guid } from "$lib/helpers";
import { http_delete, http_get, http_post } from "./internal-fetch";
import type { WorkCategory } from "$lib/models/work/WorkCategory";
import type { WorkLabel } from "$lib/models/work/WorkLabel";
import type { WorkEntry } from "$lib/models/work/WorkEntry";
import type { WorkQuery } from "$lib/models/work/WorkQuery";
import type { IInternalFetchResponse } from "$lib/models/internal/IInternalFetchResponse";
// ENTRIES
export async function create_time_entry(payload: WorkEntry): Promise<IInternalFetchResponse> {
return http_post(api_base("v1/entries/create"), payload);
}
export async function get_time_entry(entryId: string): Promise<IInternalFetchResponse> {
if (is_guid(entryId)) {
return http_get(api_base("v1/entries/" + entryId));
}
throw new Error("entryId is not a valid guid.");
}
export async function get_time_entries(entryQuery: WorkQuery): Promise<IInternalFetchResponse> {
return http_post(api_base("v1/entries/query"), entryQuery);
}
export async function delete_time_entry(id: string): Promise<IInternalFetchResponse> {
if (!is_guid(id)) throw new Error("id is not a valid guid");
return http_delete(api_base("v1/entries/" + id + "/delete"));
}
export async function update_time_entry(entryDto: WorkEntry): Promise<IInternalFetchResponse> {
if (!is_guid(entryDto.id ?? "")) throw new Error("id is not a valid guid");
if (!entryDto.category) throw new Error("category is empty");
if (!entryDto.stop) throw new Error("stop is empty");
if (!entryDto.start) throw new Error("start is empty");
return http_post(api_base("v1/entries/update"), entryDto);
}
// LABELS
export async function create_time_label(labelDto: WorkLabel): Promise<IInternalFetchResponse> {
return http_post(api_base("v1/labels/create"), labelDto);
}
export async function get_time_labels(): Promise<IInternalFetchResponse> {
return http_get(api_base("v1/labels"));
}
export async function delete_time_label(id: string): Promise<IInternalFetchResponse> {
if (!is_guid(id)) throw new Error("id is not a valid guid");
return http_delete(api_base("v1/labels/" + id + "/delete"));
}
export async function update_time_label(labelDto: WorkLabel): Promise<IInternalFetchResponse> {
if (!is_guid(labelDto.id ?? "")) throw new Error("id is not a valid guid");
if (!labelDto.name) throw new Error("name is empty");
if (!labelDto.color) throw new Error("color is empty");
return http_post(api_base("v1/labels/update"), labelDto);
}
// CATEGORIES
export async function create_time_category(category: WorkCategory): Promise<IInternalFetchResponse> {
if (!category.name) throw new Error("name is empty");
if (!category.color) throw new Error("color is empty");
return http_post(api_base("v1/categories/create"), category);
}
export async function get_time_categories(): Promise<IInternalFetchResponse> {
return http_get(api_base("v1/categories"));
}
export async function delete_time_category(id: string): Promise<IInternalFetchResponse> {
if (!is_guid(id)) throw new Error("id is not a valid guid");
return http_delete(api_base("v1/categories/" + id + "/delete"));
}
export async function update_time_category(category: WorkCategory): Promise<IInternalFetchResponse> {
if (!is_guid(category.id ?? "")) throw new Error("id is not a valid guid");
if (!category.name) throw new Error("name is empty");
if (!category.color) throw new Error("color is empty");
return http_post(api_base("v1/categories/update"), category);
}
|