feat(backend): PATCH /animals/:id/csv-config endpoint
Implement TDD for new route that accepts CSV configuration with validated buckets. Route uses auditMiddleware to log config changes and delegates validation to validateCsvConfig helper from Task 2. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ const { body, query } = require('express-validator');
|
||||
const prisma = require('../lib/prisma');
|
||||
const auditMiddleware = require('../middleware/auditMiddleware');
|
||||
const { validateRequest } = require('../middleware/errorHandler');
|
||||
const { validateCsvConfig } = require('../lib/csvConfigValidation');
|
||||
|
||||
const animalValidation = [
|
||||
body('experiment_id').notEmpty().withMessage('experiment_id is required').matches(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).withMessage('experiment_id must be a valid UUID'),
|
||||
@@ -112,4 +113,24 @@ router.delete(
|
||||
}
|
||||
);
|
||||
|
||||
// PATCH /api/animals/:id/csv-config — replace entire CSV-analysis bucket config
|
||||
router.patch(
|
||||
'/:id/csv-config',
|
||||
auditMiddleware('animals', prisma.animal),
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const err = validateCsvConfig(req.body);
|
||||
if (err) return res.status(400).json({ error: err });
|
||||
|
||||
const animal = await prisma.animal.update({
|
||||
where: { id: req.params.id },
|
||||
data: { csv_analysis_config: req.body },
|
||||
});
|
||||
res.json(animal);
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user