117 lines
2.5 KiB
JavaScript
117 lines
2.5 KiB
JavaScript
const {
|
|
getLatestPrompts,
|
|
getLatestErrors,
|
|
deletePromptById,
|
|
deleteErrorById,
|
|
deleteAllPrompts,
|
|
deleteAllErrors
|
|
} = require('../controller/logs');
|
|
|
|
async function getPrompts(req, res) {
|
|
try {
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
const { rows: prompts, count } = await getLatestPrompts(limit);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: prompts,
|
|
total: count,
|
|
limit
|
|
});
|
|
} catch (error) {
|
|
console.error('Error fetching prompts:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to fetch prompts',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
async function getErrors(req, res) {
|
|
try {
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
const { rows: errors, count } = await getLatestErrors(limit);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: errors,
|
|
total: count,
|
|
limit
|
|
});
|
|
} catch (error) {
|
|
console.error('Error fetching errors:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to fetch errors',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
async function deletePrompt(req, res) {
|
|
try {
|
|
const { id } = req.params;
|
|
|
|
if (id === 'all') {
|
|
await deleteAllPrompts();
|
|
res.json({ success: true, message: 'All prompts deleted successfully' });
|
|
return;
|
|
}
|
|
|
|
const deleted = await deletePromptById(id);
|
|
if (!deleted) {
|
|
res.status(404).json({
|
|
success: false,
|
|
error: 'Prompt not found'
|
|
});
|
|
return;
|
|
}
|
|
|
|
res.json({ success: true, message: 'Prompt deleted successfully' });
|
|
} catch (error) {
|
|
console.error('Error deleting prompt:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to delete prompt',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
async function deleteError(req, res) {
|
|
try {
|
|
const { id } = req.params;
|
|
|
|
if (id === 'all') {
|
|
await deleteAllErrors();
|
|
res.json({ success: true, message: 'All errors deleted successfully' });
|
|
return;
|
|
}
|
|
|
|
const deleted = await deleteErrorById(id);
|
|
if (!deleted) {
|
|
res.status(404).json({
|
|
success: false,
|
|
error: 'Error log not found'
|
|
});
|
|
return;
|
|
}
|
|
|
|
res.json({ success: true, message: 'Error log deleted successfully' });
|
|
} catch (error) {
|
|
console.error('Error deleting error log:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to delete error log',
|
|
message: error.message
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getPrompts,
|
|
getErrors,
|
|
deletePrompt,
|
|
deleteError
|
|
};
|