modified: backend/src/controllers/databaseManagementController.ts

modified:   backend/src/controllers/dynamicApiController.ts
	modified:   backend/src/controllers/endpointController.ts
	new file:   backend/src/migrations/005_add_aql_support.sql
	new file:   backend/src/services/AqlExecutor.ts
	modified:   backend/src/types/index.ts
	modified:   frontend/src/components/EndpointModal.tsx
	modified:   frontend/src/pages/Databases.tsx
	modified:   frontend/src/types/index.ts
This commit is contained in:
GEgorov
2025-10-07 19:33:50 +03:00
parent 7d8fddfe4f
commit 713e9ba7f7
9 changed files with 793 additions and 147 deletions

View File

@@ -81,6 +81,10 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => {
script_language,
script_code,
script_queries,
aql_method,
aql_endpoint,
aql_body,
aql_query_params,
} = req.body;
if (!name || !method || !path) {
@@ -103,13 +107,21 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => {
}
}
// Валидация для типа AQL
if (execType === 'aql') {
if (!database_id || !aql_method || !aql_endpoint) {
return res.status(400).json({ error: 'Database ID, AQL method, and AQL endpoint are required for AQL execution type' });
}
}
const result = await mainPool.query(
`INSERT INTO endpoints (
name, description, method, path, database_id, sql_query, parameters,
folder_id, user_id, is_public, enable_logging,
execution_type, script_language, script_code, script_queries
execution_type, script_language, script_code, script_queries,
aql_method, aql_endpoint, aql_body, aql_query_params
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
RETURNING *`,
[
name,
@@ -127,6 +139,10 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => {
script_language || null,
script_code || null,
JSON.stringify(script_queries || []),
aql_method || null,
aql_endpoint || null,
aql_body || null,
JSON.stringify(aql_query_params || {}),
]
);
@@ -158,6 +174,10 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => {
script_language,
script_code,
script_queries,
aql_method,
aql_endpoint,
aql_body,
aql_query_params,
} = req.body;
const result = await mainPool.query(
@@ -176,8 +196,12 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => {
script_language = $12,
script_code = $13,
script_queries = $14,
aql_method = $15,
aql_endpoint = $16,
aql_body = $17,
aql_query_params = $18,
updated_at = CURRENT_TIMESTAMP
WHERE id = $15
WHERE id = $19
RETURNING *`,
[
name,
@@ -194,6 +218,10 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => {
script_language || null,
script_code || null,
script_queries ? JSON.stringify(script_queries) : null,
aql_method || null,
aql_endpoint || null,
aql_body || null,
aql_query_params ? JSON.stringify(aql_query_params) : null,
id,
]
);
@@ -242,7 +270,11 @@ export const testEndpoint = async (req: AuthRequest, res: Response) => {
execution_type,
script_language,
script_code,
script_queries
script_queries,
aql_method,
aql_endpoint,
aql_body,
aql_query_params,
} = req.body;
const execType = execution_type || 'sql';
@@ -305,6 +337,37 @@ export const testEndpoint = async (req: AuthRequest, res: Response) => {
rowCount: scriptResult.rowCount || (Array.isArray(scriptResult.data) ? scriptResult.data.length : 0),
executionTime: scriptResult.executionTime || 0,
});
} else if (execType === 'aql') {
if (!database_id) {
return res.status(400).json({ error: 'Missing database_id for AQL execution' });
}
if (!aql_method || !aql_endpoint) {
return res.status(400).json({ error: 'Missing aql_method or aql_endpoint' });
}
// Собираем параметры из тестовых значений
const requestParams: Record<string, any> = {};
if (endpoint_parameters && Array.isArray(endpoint_parameters) && parameters && Array.isArray(parameters)) {
endpoint_parameters.forEach((param: any, index: number) => {
requestParams[param.name] = parameters[index];
});
}
const { aqlExecutor } = require('../services/AqlExecutor');
const result = await aqlExecutor.executeAqlQuery(database_id, {
method: aql_method,
endpoint: aql_endpoint,
body: aql_body,
queryParams: aql_query_params,
parameters: requestParams,
});
res.json({
success: true,
data: result.rows,
rowCount: result.rowCount,
executionTime: result.executionTime,
});
} else {
return res.status(400).json({ error: 'Invalid execution_type' });
}