Add 'Mark as Cleaned Up' functionality
- Add cleaned_at and cleaned_by_user_id fields to reports table - Create database migration for cleanup tracking - Add markAsCleaned backend endpoint and service method - Add Mark as Cleaned Up button to ReportDetailModal - Update types to include cleaned fields - Add frontend handler to mark reports as cleaned
This commit is contained in:
@@ -385,6 +385,49 @@ export class ReportController {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async markAsCleaned(req: AuthRequest, res: Response) {
|
||||
try {
|
||||
if (!req.userId) {
|
||||
return res.status(401).json({
|
||||
error: {
|
||||
code: 'UNAUTHORIZED',
|
||||
message: 'User not authenticated',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const { id } = req.params;
|
||||
|
||||
// Find or create user in database
|
||||
const dbUserId = await this.findOrCreateUser(req.userId);
|
||||
|
||||
const report = await reportService.markAsCleaned(id, dbUserId);
|
||||
|
||||
res.json(report);
|
||||
} catch (error: any) {
|
||||
console.error('Error marking report as cleaned:', error);
|
||||
|
||||
if (error.message === 'Report not found') {
|
||||
return res.status(404).json({
|
||||
error: {
|
||||
code: 'RESOURCE_NOT_FOUND',
|
||||
message: 'Report not found',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
res.status(500).json({
|
||||
error: {
|
||||
code: 'INTERNAL_SERVER_ERROR',
|
||||
message: 'Failed to mark report as cleaned',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const reportController = new ReportController();
|
||||
|
||||
@@ -18,4 +18,7 @@ router.delete('/:id', requireAuth, reportController.deleteReport.bind(reportCont
|
||||
router.post('/:id/verify', requireAuth, reportController.verifyReport.bind(reportController));
|
||||
router.post('/:id/dispute', requireAuth, reportController.disputeReport.bind(reportController));
|
||||
|
||||
// Cleanup tracking
|
||||
router.post('/:id/mark-cleaned', requireAuth, reportController.markAsCleaned.bind(reportController));
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -330,6 +330,29 @@ export class ReportService {
|
||||
data: { verificationStatus: status },
|
||||
});
|
||||
}
|
||||
|
||||
async markAsCleaned(reportId: string, userId: string) {
|
||||
// Check if report exists
|
||||
const report = await prisma.report.findUnique({
|
||||
where: { id: reportId },
|
||||
});
|
||||
|
||||
if (!report) {
|
||||
throw new Error('Report not found');
|
||||
}
|
||||
|
||||
// Mark as cleaned
|
||||
await prisma.report.update({
|
||||
where: { id: reportId },
|
||||
data: {
|
||||
cleanedAt: new Date(),
|
||||
cleanedByUserId: userId,
|
||||
},
|
||||
});
|
||||
|
||||
// Return updated report
|
||||
return this.getReportById(reportId);
|
||||
}
|
||||
}
|
||||
|
||||
export const reportService = new ReportService();
|
||||
|
||||
Reference in New Issue
Block a user