sensor and location done and some cleanupd
testing will be required
This commit is contained in:
77
Sean/modules/validationMiddleware.js
Normal file
77
Sean/modules/validationMiddleware.js
Normal file
@ -0,0 +1,77 @@
|
||||
const { body } = require('express-validator');
|
||||
|
||||
const locationValidation = [
|
||||
body('name').trim().isLength({ min: 1 }).withMessage('Name must not be empty').escape(),
|
||||
body('added_by').trim().isLength({ min: 1 }).withMessage('Added by must not be empty').escape(),
|
||||
body('description').trim().escape(),
|
||||
];
|
||||
|
||||
const locationValidationUpdate = [
|
||||
body('id').trim().escape(),
|
||||
body('name').trim().isLength({ min: 1 }).withMessage('Name must not be empty').escape(),
|
||||
body('added_by').trim().isLength({ min: 1 }).withMessage('Added by must not be empty').escape(),
|
||||
body('description').trim().escape(),
|
||||
];
|
||||
|
||||
const locationdeleteValidation = [
|
||||
body('id').trim().escape()
|
||||
];
|
||||
|
||||
const sensorValidation = [
|
||||
body('sensorname').trim().isLength({ min: 1 }).withMessage('Sensor Name must not be empty').escape(),
|
||||
body('added_by').trim().isLength({ min: 1 }).withMessage('Added by must not be empty').escape(),
|
||||
body('macAddress').custom(value => {
|
||||
const macAddressRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
|
||||
if (!macAddressRegex.test(value)) {
|
||||
throw new Error('Invalid MAC address format');
|
||||
}
|
||||
return true;
|
||||
}).withMessage('Invalid MAC address format').escape(),
|
||||
body('description').trim().escape(),
|
||||
body('location').trim().escape()
|
||||
];
|
||||
|
||||
const sensorupdateValidation = [
|
||||
body('id').trim().escape(),
|
||||
body('sensorname').trim().isLength({ min: 1 }).withMessage('Sensor Name must not be empty').escape(),
|
||||
body('added_by').trim().isLength({ min: 1 }).withMessage('Added by must not be empty').escape(),
|
||||
body('macAddress').custom(value => {
|
||||
const macAddressRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
|
||||
if (!macAddressRegex.test(value)) {
|
||||
throw new Error('Invalid MAC address format');
|
||||
}
|
||||
return true;
|
||||
}).withMessage('Invalid MAC address format').escape(),
|
||||
body('description').trim().escape(),
|
||||
body('location').trim().escape()
|
||||
];
|
||||
|
||||
const sensordeleteValidation = [
|
||||
body('id').trim().escape()
|
||||
];
|
||||
|
||||
const loginValidation = [
|
||||
body('username').escape().trim().isLength({ min: 1 }).withMessage('Username must not be empty'),
|
||||
body('password').escape().trim().isLength({ min: 1 }).withMessage('Password must not be empty'),
|
||||
];
|
||||
|
||||
const otpValidation = [
|
||||
body('otp').escape().trim().isLength({ min: 1 }).withMessage('OTP must not be empty'),
|
||||
];
|
||||
|
||||
const createValidation = [
|
||||
body('name').trim().isLength({ min: 1 }).withMessage('Name must not be empty').escape(),
|
||||
body('username').trim().isLength({ min: 1 }).withMessage('Username must not be empty').escape(),
|
||||
body('email').isEmail().withMessage('Invalid email address').normalizeEmail(),
|
||||
body('password').custom((value) => {
|
||||
if (!isStrongPassword(value)) { throw new Error('Password does not meet complexity requirements'); } return true;
|
||||
}),
|
||||
body('jobTitle').trim().isLength({ min: 1 }).withMessage('Job title must not be empty').escape(),
|
||||
];
|
||||
|
||||
|
||||
module.exports = {
|
||||
locationValidation,locationValidationUpdate,locationdeleteValidation
|
||||
,sensorValidation,sensorupdateValidation,sensordeleteValidation,loginValidation,otpValidation
|
||||
,createValidation
|
||||
};
|
Reference in New Issue
Block a user