Initial commit: added frontend and backend
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
const Report = require('../models/Report');
|
||||
const User = require('../models/User');
|
||||
|
||||
exports.createReport = async (req, res) => {
|
||||
try {
|
||||
const { reportId, phone, userName, data, link } = req.body;
|
||||
|
||||
if (!reportId || !phone || !data) {
|
||||
return res.status(400).json({ success: false, message: 'Missing required fields' });
|
||||
}
|
||||
|
||||
const report = await Report.create({
|
||||
reportId,
|
||||
phone,
|
||||
userName,
|
||||
data,
|
||||
link
|
||||
});
|
||||
|
||||
res.status(201).json({ success: true, report });
|
||||
} catch (error) {
|
||||
console.error('Error creating report:', error);
|
||||
res.status(500).json({ success: false, message: 'Server error' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.getReport = async (req, res) => {
|
||||
try {
|
||||
const { reportId } = req.params;
|
||||
|
||||
const report = await Report.findOne({ reportId });
|
||||
|
||||
if (!report) {
|
||||
return res.status(404).json({ success: false, message: 'Report not found' });
|
||||
}
|
||||
|
||||
// Return the report data directly to match frontend expectation
|
||||
res.json(report.data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching report:', error);
|
||||
res.status(500).json({ success: false, message: 'Server error' });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user