modified: backend/src/controllers/dynamicApiController.ts

modified:   backend/src/controllers/endpointController.ts
	new file:   backend/src/migrations/007_add_detailed_response.sql
	modified:   frontend/src/components/EndpointModal.tsx
	modified:   frontend/src/types/index.ts
This commit is contained in:
2025-12-18 14:50:33 +03:00
parent a5d726cf1f
commit 58a319b66c
5 changed files with 41 additions and 10 deletions

View File

@@ -233,12 +233,16 @@ export const executeDynamicEndpoint = async (req: ApiKeyRequest, res: Response)
);
}
const responseData = {
// Build response based on detailed_response flag
const detailedResponse = endpoint.detailed_response || false;
const responseData = detailedResponse
? {
success: true,
data: result.rows,
rowCount: result.rowCount,
executionTime: result.executionTime,
};
}
: result.rows;
// Log if needed
if (shouldLog && endpointId) {

View File

@@ -85,6 +85,7 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => {
aql_endpoint,
aql_body,
aql_query_params,
detailed_response,
} = req.body;
if (!name || !method || !path) {
@@ -119,9 +120,9 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => {
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,
aql_method, aql_endpoint, aql_body, aql_query_params
aql_method, aql_endpoint, aql_body, aql_query_params, detailed_response
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
RETURNING *`,
[
name,
@@ -143,6 +144,7 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => {
aql_endpoint || null,
aql_body || null,
JSON.stringify(aql_query_params || {}),
detailed_response || false,
]
);
@@ -178,6 +180,7 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => {
aql_endpoint,
aql_body,
aql_query_params,
detailed_response,
} = req.body;
const result = await mainPool.query(
@@ -200,8 +203,9 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => {
aql_endpoint = $16,
aql_body = $17,
aql_query_params = $18,
detailed_response = $19,
updated_at = CURRENT_TIMESTAMP
WHERE id = $19
WHERE id = $20
RETURNING *`,
[
name,
@@ -222,6 +226,7 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => {
aql_endpoint || null,
aql_body || null,
aql_query_params ? JSON.stringify(aql_query_params) : null,
detailed_response || false,
id,
]
);

View File

@@ -0,0 +1,8 @@
-- Add detailed_response flag to endpoints
-- When false (default): returns only data array
-- When true: returns full response with success, data, rowCount, executionTime
ALTER TABLE endpoints
ADD COLUMN IF NOT EXISTS detailed_response BOOLEAN DEFAULT false;
COMMENT ON COLUMN endpoints.detailed_response IS 'If true, returns detailed response with rowCount and executionTime. Default returns only data array.';

View File

@@ -41,6 +41,8 @@ export default function EndpointModal({
aql_endpoint: endpoint?.aql_endpoint || '',
aql_body: endpoint?.aql_body || '',
aql_query_params: endpoint?.aql_query_params || {},
// Response format
detailed_response: endpoint?.detailed_response || false,
});
const [editingQueryIndex, setEditingQueryIndex] = useState<number | null>(null);
@@ -592,7 +594,7 @@ export default function EndpointModal({
</>
)}
<div className="flex items-center gap-6">
<div className="flex flex-wrap items-center gap-6">
<label className="flex items-center gap-2">
<input
type="checkbox"
@@ -612,6 +614,16 @@ export default function EndpointModal({
/>
<span className="text-sm text-gray-700">Логгировать запросы</span>
</label>
<label className="flex items-center gap-2">
<input
type="checkbox"
checked={formData.detailed_response}
onChange={(e) => setFormData({ ...formData, detailed_response: e.target.checked })}
className="rounded"
/>
<span className="text-sm text-gray-700">Детализировать ответ (rowCount, executionTime)</span>
</label>
</div>
{formData.parameters.length > 0 && (

View File

@@ -78,6 +78,8 @@ export interface Endpoint {
aql_endpoint?: string;
aql_body?: string;
aql_query_params?: Record<string, string>;
// Response format
detailed_response?: boolean;
created_at: string;
updated_at: string;
}