refactor
This commit is contained in:
105
api/sections.ts
105
api/sections.ts
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user