This commit is contained in:
taDuc
2026-04-20 23:27:38 +07:00
parent 2508172489
commit 3ca7098831
36 changed files with 1939 additions and 1695 deletions

View File

@@ -1,17 +1,8 @@
import { API_ENDPOINTS } from "@/api/config";
import { requestJson } from "@/api/http";
import type { Entity } from "@/types/entities";
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 { Entity } from "@/types/entities";
export async function fetchEntities(query?: { q?: string }): Promise<Entity[]> {
const params = new URLSearchParams();

View File

@@ -1,15 +1,9 @@
import { API_ENDPOINTS } from "@/api/config";
import { requestJson } from "@/api/http";
import { FeatureCollection } from "@/lib/useEditorState";
import type { GeometriesBBoxQuery } from "@/types/api";
import type { FeatureCollection } from "@/types/geo";
export type GeometriesBBoxQuery = {
minLng: number;
minLat: number;
maxLng: number;
maxLat: number;
time?: number;
entity_id?: string;
};
export type { GeometriesBBoxQuery } from "@/types/api";
function buildBBoxQueryString(params: GeometriesBBoxQuery): string {
const query = new URLSearchParams({

View File

@@ -1,3 +1,5 @@
import type { ApiEnvelope } from "@/types/api";
export class ApiError extends Error {
status: number;
body: string;
@@ -12,13 +14,6 @@ export class ApiError extends Error {
}
}
type ApiEnvelope<T> = {
status: "success" | "error" | string;
data: T;
message: string;
errors: unknown[];
};
export async function requestJson<T>(input: RequestInfo | URL, init?: RequestInit): Promise<T> {
const res = await fetch(input, init);
const payload = await parseJsonResponse(res);

View File

@@ -1,81 +1,26 @@
import { API_ENDPOINTS } from "@/api/config";
import { jsonRequestInit, requestJson } from "@/api/http";
import type {
CreateCommitInput,
CreateSectionInput,
EditorLoadResponse,
RestoreCommitInput,
Section,
SectionCommit,
SectionState,
SectionSubmission,
} from "@/types/sections";
export type SectionState = {
section_id?: string;
status: "editing" | "submitted" | "approved" | "rejected";
head_commit_id: string | null;
version: number;
locked_by: string | null;
locked_at: string | null;
lock_expires_at: string | null;
updated_at?: string;
};
export type Section = {
id: string;
title: string;
description: string | null;
user_id: string | null;
created_by: string | null;
created_at: string;
updated_at: string;
state: Omit<SectionState, "section_id" | "updated_at">;
};
export type SectionCommit = {
id: string;
section_id: string;
parent_commit_id: string | null;
commit_no: number;
kind: "manual" | "restore";
restored_from_commit_id: string | null;
created_by: string;
created_at: string;
title: string | null;
note: string | null;
snapshot_hash: string | null;
snapshot?: unknown;
};
export type SectionSubmission = {
id: string;
section_id: string;
commit_id: string;
submitted_by: string;
submitted_at: string;
status: "pending" | "approved" | "rejected" | "conflicted";
reviewed_by: string | null;
reviewed_at: string | null;
review_note: string | null;
snapshot_hash: string | null;
snapshot?: unknown;
};
export type EditorLoadResponse = {
section: Section;
state: SectionState;
commit: SectionCommit | null;
snapshot: unknown;
};
export type CreateSectionInput = {
id?: string;
title: string;
description?: string | null;
user_id?: string;
created_by?: string;
};
export type CreateCommitInput = {
snapshot: unknown;
created_by?: string;
user_id?: string;
expected_version?: number;
expected_head_commit_id?: string | null;
title?: string | null;
note?: string | null;
};
export type {
CreateCommitInput,
CreateSectionInput,
EditorLoadResponse,
RestoreCommitInput,
Section,
SectionCommit,
SectionState,
SectionSubmission,
} from "@/types/sections";
export async function fetchSections(): Promise<Section[]> {
return requestJson<Section[]>(API_ENDPOINTS.sections);
@@ -126,15 +71,7 @@ export async function fetchSectionCommits(
export async function restoreSectionCommit(
sectionId: string,
input: {
commit_id: string;
created_by?: string;
user_id?: string;
expected_version?: number;
expected_head_commit_id?: string | null;
title?: string | null;
note?: string | null;
}
input: RestoreCommitInput
): Promise<{ commit: SectionCommit; state: SectionState }> {
return requestJson<{ commit: SectionCommit; state: SectionState }>(
sectionUrl(sectionId, "restore"),