|
@@ -1,8 +1,8 @@
|
|
-const express = require('express');
|
|
|
|
|
|
+const express = require("express");
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
-const { executeQuery } = require('../config/database');
|
|
|
|
|
|
+const { executeQuery } = require("../config/database");
|
|
|
|
|
|
-router.get('/', async (req, res) => {
|
|
|
|
|
|
+router.get("/", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { page = 1, pageSize = 10 } = req.query;
|
|
const { page = 1, pageSize = 10 } = req.query;
|
|
const offset = (page - 1) * pageSize;
|
|
const offset = (page - 1) * pageSize;
|
|
@@ -20,22 +20,22 @@ router.get('/', async (req, res) => {
|
|
|
|
|
|
const [data, countResult] = await Promise.all([
|
|
const [data, countResult] = await Promise.all([
|
|
executeQuery(sql, [parseInt(pageSize), offset]),
|
|
executeQuery(sql, [parseInt(pageSize), offset]),
|
|
- executeQuery(countSql)
|
|
|
|
|
|
+ executeQuery(countSql),
|
|
]);
|
|
]);
|
|
|
|
|
|
res.json({
|
|
res.json({
|
|
data,
|
|
data,
|
|
total: countResult[0].total,
|
|
total: countResult[0].total,
|
|
page: parseInt(page),
|
|
page: parseInt(page),
|
|
- pageSize: parseInt(pageSize)
|
|
|
|
|
|
+ pageSize: parseInt(pageSize),
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error fetching tools library:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error fetching tools library:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.get('/:id', async (req, res) => {
|
|
|
|
|
|
+router.get("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
|
|
|
|
@@ -51,23 +51,33 @@ router.get('/:id', async (req, res) => {
|
|
const data = await executeQuery(sql, [id]);
|
|
const data = await executeQuery(sql, [id]);
|
|
|
|
|
|
if (data.length === 0) {
|
|
if (data.length === 0) {
|
|
- return res.status(404).json({ error: 'Tool not found' });
|
|
|
|
|
|
+ return res.status(404).json({ error: "Tool not found" });
|
|
}
|
|
}
|
|
|
|
|
|
res.json(data[0]);
|
|
res.json(data[0]);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error fetching tool detail:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error fetching tool detail:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.put('/:id', async (req, res) => {
|
|
|
|
|
|
+router.put("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
const {
|
|
const {
|
|
- tools_name, tools_function_name, tools_full_name, tools_desc,
|
|
|
|
- tools_version, access_task_id, status, call_type, api_provider,
|
|
|
|
- api_url_path, operate_path_data, params_definition, response_desc
|
|
|
|
|
|
+ tools_name,
|
|
|
|
+ tools_function_name,
|
|
|
|
+ tools_full_name,
|
|
|
|
+ tools_desc,
|
|
|
|
+ tools_version,
|
|
|
|
+ access_task_id,
|
|
|
|
+ status,
|
|
|
|
+ call_type,
|
|
|
|
+ api_provider,
|
|
|
|
+ api_url_path,
|
|
|
|
+ operate_path_data,
|
|
|
|
+ params_definition,
|
|
|
|
+ response_desc,
|
|
} = req.body;
|
|
} = req.body;
|
|
|
|
|
|
const sql = `
|
|
const sql = `
|
|
@@ -81,19 +91,30 @@ router.put('/:id', async (req, res) => {
|
|
`;
|
|
`;
|
|
|
|
|
|
await executeQuery(sql, [
|
|
await executeQuery(sql, [
|
|
- tools_name, tools_function_name, tools_full_name, tools_desc,
|
|
|
|
- tools_version, access_task_id, status, call_type, api_provider,
|
|
|
|
- api_url_path, operate_path_data, params_definition, response_desc, id
|
|
|
|
|
|
+ tools_name,
|
|
|
|
+ tools_function_name,
|
|
|
|
+ tools_full_name,
|
|
|
|
+ tools_desc,
|
|
|
|
+ tools_version,
|
|
|
|
+ access_task_id,
|
|
|
|
+ status,
|
|
|
|
+ call_type,
|
|
|
|
+ api_provider,
|
|
|
|
+ api_url_path,
|
|
|
|
+ operate_path_data,
|
|
|
|
+ params_definition,
|
|
|
|
+ response_desc,
|
|
|
|
+ id,
|
|
]);
|
|
]);
|
|
|
|
|
|
- res.json({ message: 'Tool updated successfully' });
|
|
|
|
|
|
+ res.json({ message: "Tool updated successfully" });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error updating tool:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error updating tool:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.post('/:id/publish', async (req, res) => {
|
|
|
|
|
|
+router.post("/:id/publish", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
|
|
|
|
@@ -105,11 +126,11 @@ router.post('/:id/publish', async (req, res) => {
|
|
|
|
|
|
await executeQuery(sql, [id]);
|
|
await executeQuery(sql, [id]);
|
|
|
|
|
|
- res.json({ message: 'Tool published successfully' });
|
|
|
|
|
|
+ res.json({ message: "Tool published successfully" });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error publishing tool:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error publishing tool:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-module.exports = router;
|
|
|
|
|
|
+module.exports = router;
|