File size: 1,889 Bytes
c993983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import client from './client';
import type { ProcessNode } from '../types/process';

// Process groups
export async function addGroup(projectId: string, name: string) {
  const res = await client.post(`/api/projects/${projectId}/groups`, { name });
  return res.data;
}

export async function updateGroup(projectId: string, groupIdx: number, name: string) {
  const res = await client.put(`/api/projects/${projectId}/groups/${groupIdx}`, { name });
  return res.data;
}

export async function deleteGroup(projectId: string, groupIdx: number) {
  const res = await client.delete(`/api/projects/${projectId}/groups/${groupIdx}`);
  return res.data;
}

// Subprocesses
export async function addSubprocess(projectId: string, groupIdx: number, node?: ProcessNode) {
  const res = await client.post(`/api/projects/${projectId}/groups/${groupIdx}/procs`, node ?? null);
  return res.data;
}

export async function updateSubprocess(projectId: string, procIdx: number, node: ProcessNode) {
  const res = await client.put(`/api/procs/${projectId}/${procIdx}`, node);
  return res.data;
}

export async function deleteSubprocess(projectId: string, procIdx: number) {
  const res = await client.delete(`/api/procs/${projectId}/${procIdx}`);
  return res.data;
}

// Children
export async function addChild(projectId: string, procIdx: number, node?: ProcessNode) {
  const res = await client.post(`/api/procs/${projectId}/${procIdx}/children`, node ?? null);
  return res.data;
}

export async function deleteChild(projectId: string, procIdx: number, childIdx: number) {
  const res = await client.delete(`/api/procs/${projectId}/${procIdx}/children/${childIdx}`);
  return res.data;
}

// Geocoding
export async function geoSearch(query: string) {
  const res = await client.post('/api/geo/search', { query });
  return res.data.results as Array<{ display_name: string; lat: number; lon: number }>;
}