Files
apiAi/src/controllers/logsController.js

54 lines
1.3 KiB
JavaScript

const Prompt = require('../models/Prompt');
const ErrorLog = require('../models/Error');
class LogsController {
/**
* Get latest prompts
* @param {Object} req - Express request object
* @param {Object} res - Express response object
*/
static async getLatestPrompts(req, res) {
try {
const limit = parseInt(req.query.limit) || 100;
const prompts = await Prompt.getLatest(limit);
res.json({
success: true,
data: prompts
});
} catch (error) {
console.error('Error fetching prompts:', error);
res.status(500).json({
success: false,
error: 'Internal Server Error',
message: 'Failed to fetch prompts'
});
}
}
/**
* Get latest error logs
* @param {Object} req - Express request object
* @param {Object} res - Express response object
*/
static async getLatestErrors(req, res) {
try {
const limit = parseInt(req.query.limit) || 100;
const errors = await ErrorLog.getLatest(limit);
res.json({
success: true,
data: errors
});
} catch (error) {
console.error('Error fetching error logs:', error);
res.status(500).json({
success: false,
error: 'Internal Server Error',
message: 'Failed to fetch error logs'
});
}
}
}
module.exports = LogsController;