Spaces:
Sleeping
Sleeping
File size: 1,312 Bytes
83f4356 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | const { supabaseAdmin } = require('../config/supabase');
const { success, created, error, serverError } = require('../utils/response');
/**
* POST /api/user-reports — submit a report about a user
*/
async function createReport(req, res) {
try {
const { reported_user_id, reason, description } = req.body;
if (!reported_user_id || !reason) {
return error(res, 'reported_user_id and reason are required', 400);
}
if (reported_user_id === req.user.id) {
return error(res, 'You cannot report yourself', 400);
}
// Verify reported user exists
const { data: reportedUser } = await supabaseAdmin
.from('profiles')
.select('id')
.eq('id', reported_user_id)
.single();
if (!reportedUser) {
return error(res, 'Reported user not found', 404);
}
const { data, error: dbError } = await supabaseAdmin
.from('user_reports')
.insert({
reporter_id: req.user.id,
reported_user_id,
reason,
description: description || null,
})
.select()
.single();
if (dbError) return error(res, dbError.message, 400);
return created(res, data);
} catch (err) {
console.error('createReport error:', err);
return serverError(res);
}
}
module.exports = { createReport };
|