Files
adopt-a-street/backend/middleware/validators/eventValidator.js
William Valentin 9ac21fca72 feat: migrate Event and Reward models from MongoDB to CouchDB
- Replace Event model with CouchDB version using couchdbService
- Replace Reward model with CouchDB version using couchdbService
- Update event and reward routes to use new model interfaces
- Handle participant management with embedded user data
- Maintain status transitions for events (upcoming, ongoing, completed, cancelled)
- Preserve catalog functionality and premium vs regular rewards
- Update validators to accept CouchDB document IDs
- Add rewards design document to couchdbService
- Update test helpers for new model structure
- Initialize CouchDB alongside MongoDB in server.js for backward compatibility
- Fix linting issues in migrated routes

🤖 Generated with [AI Assistant]

Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
2025-11-01 13:26:00 -07:00

70 lines
1.6 KiB
JavaScript

const { body, param, validationResult } = require("express-validator");
const validate = (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({
success: false,
errors: errors.array().map((err) => ({
field: err.path,
message: err.msg,
})),
});
}
next();
};
/**
* Create event validation
*/
const createEventValidation = [
body("title")
.trim()
.notEmpty()
.withMessage("Event title is required")
.isLength({ min: 3, max: 200 })
.withMessage("Title must be between 3 and 200 characters"),
body("description")
.trim()
.notEmpty()
.withMessage("Event description is required")
.isLength({ min: 10, max: 1000 })
.withMessage("Description must be between 10 and 1000 characters"),
body("date")
.notEmpty()
.withMessage("Event date is required")
.isISO8601()
.withMessage("Date must be a valid ISO 8601 date")
.custom((value) => {
if (new Date(value) < new Date()) {
throw new Error("Event date must be in the future");
}
return true;
}),
body("location")
.trim()
.notEmpty()
.withMessage("Event location is required")
.isLength({ min: 3, max: 200 })
.withMessage("Location must be between 3 and 200 characters"),
validate,
];
/**
* Event ID validation
*/
const eventIdValidation = [
param("id")
.notEmpty()
.withMessage("Event ID is required")
.matches(/^(event_[a-zA-Z0-9]+|[0-9a-fA-F]{24})$/)
.withMessage("Invalid event ID format"),
validate,
];
module.exports = {
createEventValidation,
eventIdValidation,
validate,
};