51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const { body, validationResult } = require('express-validator');
|
|
|
|
const handleValidationErrors = (req, res, next) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
message: 'Validierungsfehler',
|
|
errors: errors.array()
|
|
});
|
|
}
|
|
next();
|
|
};
|
|
|
|
const validateLogin = [
|
|
body('username')
|
|
.trim()
|
|
.notEmpty()
|
|
.withMessage('Benutzername ist erforderlich'),
|
|
body('password')
|
|
.notEmpty()
|
|
.withMessage('Passwort ist erforderlich')
|
|
.isLength({ min: 6 })
|
|
.withMessage('Passwort muss mindestens 6 Zeichen lang sein'),
|
|
handleValidationErrors
|
|
];
|
|
|
|
const validateGPS = [
|
|
body('lat')
|
|
.isFloat({ min: -90, max: 90 })
|
|
.withMessage('Latitude muss zwischen -90 und 90 liegen'),
|
|
body('lng')
|
|
.isFloat({ min: -180, max: 180 })
|
|
.withMessage('Longitude muss zwischen -180 und 180 liegen'),
|
|
handleValidationErrors
|
|
];
|
|
|
|
const validateAvailability = [
|
|
body('available')
|
|
.isBoolean()
|
|
.withMessage('Verfügbarkeit muss ein Boolean-Wert sein'),
|
|
handleValidationErrors
|
|
];
|
|
|
|
module.exports = {
|
|
validateLogin,
|
|
validateGPS,
|
|
validateAvailability,
|
|
handleValidationErrors
|
|
};
|