35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
|
|
const router = require('express').Router();
|
||
|
|
const { standardizeError } = require('../middleware/errorFormatter');
|
||
|
|
const {
|
||
|
|
listMatchSuggestions,
|
||
|
|
rejectMatchSuggestion,
|
||
|
|
} = require('../services/matchSuggestionService');
|
||
|
|
|
||
|
|
function sendMatchError(res, err, fallbackMessage = 'Match operation failed') {
|
||
|
|
if (err.status) {
|
||
|
|
return res.status(err.status).json(standardizeError(err.message, err.code || 'MATCH_ERROR', err.field));
|
||
|
|
}
|
||
|
|
console.error('[matches] service error:', err.stack || err.message);
|
||
|
|
return res.status(500).json(standardizeError(fallbackMessage, 'MATCH_ERROR'));
|
||
|
|
}
|
||
|
|
|
||
|
|
// GET /api/matches/suggestions
|
||
|
|
router.get('/suggestions', (req, res) => {
|
||
|
|
try {
|
||
|
|
res.json(listMatchSuggestions(req.user.id, req.query));
|
||
|
|
} catch (err) {
|
||
|
|
return sendMatchError(res, err, 'Match suggestions failed');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// POST /api/matches/:id/reject
|
||
|
|
router.post('/:id/reject', (req, res) => {
|
||
|
|
try {
|
||
|
|
res.json(rejectMatchSuggestion(req.user.id, req.params.id));
|
||
|
|
} catch (err) {
|
||
|
|
return sendMatchError(res, err, 'Rejecting match suggestion failed');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
module.exports = router;
|