ERP-node/frontend/lib/api/ddl.ts

136 lines
3.2 KiB
TypeScript
Raw Permalink Normal View History

/**
* DDL API
*/
import { apiClient } from "./client";
import {
CreateTableRequest,
AddColumnRequest,
DDLExecutionResult,
ValidationResult,
DDLExecutionLog,
DDLStatistics,
} from "../../types/ddl";
export const ddlApi = {
/**
*
*/
createTable: async (request: CreateTableRequest): Promise<DDLExecutionResult> => {
const response = await apiClient.post("/ddl/tables", request);
return response.data;
},
/**
*
*/
addColumn: async (tableName: string, request: AddColumnRequest): Promise<DDLExecutionResult> => {
const response = await apiClient.post(`/ddl/tables/${tableName}/columns`, request);
return response.data;
},
/**
* (DROP TABLE)
*/
dropTable: async (tableName: string): Promise<DDLExecutionResult> => {
const response = await apiClient.delete(`/ddl/tables/${tableName}`);
return response.data;
},
/**
* ( )
*/
validateTableCreation: async (request: CreateTableRequest): Promise<ValidationResult> => {
const response = await apiClient.post("/ddl/validate/table", request);
return response.data.data;
},
/**
* DDL
*/
getDDLLogs: async (params?: {
limit?: number;
userId?: string;
ddlType?: string;
}): Promise<{
logs: DDLExecutionLog[];
total: number;
}> => {
const response = await apiClient.get("/ddl/logs", { params });
return response.data.data;
},
/**
* DDL
*/
getDDLStatistics: async (params?: { fromDate?: string; toDate?: string }): Promise<DDLStatistics> => {
const response = await apiClient.get("/ddl/statistics", { params });
return response.data.data;
},
/**
* DDL
*/
getTableDDLHistory: async (
tableName: string,
): Promise<{
tableName: string;
history: DDLExecutionLog[];
total: number;
}> => {
const response = await apiClient.get(`/ddl/tables/${tableName}/history`);
return response.data.data;
},
/**
*
*/
getTableInfo: async (
tableName: string,
): Promise<{
tableInfo: any;
columns: any[];
}> => {
const response = await apiClient.get(`/ddl/tables/${tableName}/info`);
return response.data.data;
},
/**
* DDL
*/
cleanupOldLogs: async (
retentionDays?: number,
): Promise<{
deletedCount: number;
retentionDays: number;
}> => {
const response = await apiClient.delete("/ddl/logs/cleanup", {
params: { retentionDays },
});
return response.data.data;
},
/**
* DDL
*/
getServiceInfo: async (): Promise<any> => {
const response = await apiClient.get("/ddl/info");
return response.data.data;
},
/**
* DDL
*/
healthCheck: async (): Promise<{
status: string;
timestamp: string;
checks: {
database: string;
service: string;
};
}> => {
const response = await apiClient.get("/ddl/health");
return response.data;
},
};