first commit: Complete phishing test management panel with Node.js backend and React frontend
This commit is contained in:
59
backend/src/validators/token.validator.js
Normal file
59
backend/src/validators/token.validator.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const Joi = require('joi');
|
||||
|
||||
const createTokenSchema = Joi.object({
|
||||
company_id: Joi.number()
|
||||
.integer()
|
||||
.positive()
|
||||
.required()
|
||||
.messages({
|
||||
'number.base': 'Company ID must be a number',
|
||||
'any.required': 'Company ID is required',
|
||||
}),
|
||||
target_email: Joi.string()
|
||||
.email()
|
||||
.required()
|
||||
.messages({
|
||||
'string.email': 'Valid email is required',
|
||||
'any.required': 'Target email is required',
|
||||
}),
|
||||
employee_name: Joi.string()
|
||||
.max(255)
|
||||
.allow(null, '')
|
||||
.optional(),
|
||||
template_type: Joi.string()
|
||||
.max(50)
|
||||
.default('bank')
|
||||
.required()
|
||||
.messages({
|
||||
'any.required': 'Template type is required',
|
||||
}),
|
||||
});
|
||||
|
||||
const updateTokenSchema = Joi.object({
|
||||
notes: Joi.string()
|
||||
.max(1000)
|
||||
.allow(null, '')
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const validate = (schema) => {
|
||||
return (req, res, next) => {
|
||||
const { error } = schema.validate(req.body, { abortEarly: false });
|
||||
|
||||
if (error) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'Validation error',
|
||||
details: error.details.map(d => d.message),
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateCreateToken: validate(createTokenSchema),
|
||||
validateUpdateToken: validate(updateTokenSchema),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user