draw path | draw area | localstorage layer state | add entities property parallel | timeline bar
This commit is contained in:
48
api/entities.ts
Normal file
48
api/entities.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { API_ENDPOINTS } from "@/api/config";
|
||||
import { requestJson } from "@/api/http";
|
||||
|
||||
export type Entity = {
|
||||
id: string;
|
||||
name: string;
|
||||
slug?: string | null;
|
||||
description?: string | null;
|
||||
type_id?: string | null;
|
||||
status?: number | null;
|
||||
geometry_count?: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
|
||||
export type CreateEntityPayload = {
|
||||
name: string;
|
||||
slug?: string | null;
|
||||
description?: string | null;
|
||||
type_id?: string | null;
|
||||
status?: number | null;
|
||||
};
|
||||
|
||||
export async function fetchEntities(query?: { q?: string }): Promise<Entity[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.q) {
|
||||
params.set("q", query.q);
|
||||
}
|
||||
const suffix = params.toString();
|
||||
const url = suffix ? `${API_ENDPOINTS.entities}?${suffix}` : API_ENDPOINTS.entities;
|
||||
return requestJson<Entity[]>(url);
|
||||
}
|
||||
|
||||
export async function createEntity(payload: CreateEntityPayload): Promise<Entity> {
|
||||
return requestJson<Entity>(API_ENDPOINTS.entities, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateEntity(id: string, payload: CreateEntityPayload): Promise<Entity> {
|
||||
return requestJson<Entity>(`${API_ENDPOINTS.entities}/${id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user