- Added full CRUD endpoints for mail templates (create, update, delete, preview) - Introduced Joi validators for template create/update/preview - Updated routes/controller to support ID and type lookups - Built React Templates page with HTML editor, preview, and clipboard helpers - Added navigation entry and route for /templates - Enhanced documentation (README, QUICKSTART, KULLANIM, frontend/backend README)
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
const Joi = require('joi');
|
|
|
|
const baseSchema = {
|
|
name: Joi.string().max(255).required(),
|
|
template_type: Joi.string().max(50).required(),
|
|
subject_template: Joi.string().max(500).allow('', null),
|
|
body_html: Joi.string().required(),
|
|
description: Joi.string().allow('', null),
|
|
active: Joi.boolean().default(true),
|
|
};
|
|
|
|
const createSchema = Joi.object(baseSchema);
|
|
|
|
const updateSchema = Joi.object({
|
|
...baseSchema,
|
|
});
|
|
|
|
const previewSchema = Joi.object({
|
|
template_html: Joi.string().required(),
|
|
company_name: Joi.string().allow('', null),
|
|
employee_name: Joi.string().allow('', null),
|
|
});
|
|
|
|
exports.validateCreateTemplate = (req, res, next) => {
|
|
const { error, value } = createSchema.validate(req.body, { abortEarly: false });
|
|
if (error) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: 'Validation failed',
|
|
details: error.details.map((detail) => detail.message),
|
|
});
|
|
}
|
|
req.body = value;
|
|
next();
|
|
};
|
|
|
|
exports.validateUpdateTemplate = (req, res, next) => {
|
|
const { error, value } = updateSchema.validate(req.body, { abortEarly: false });
|
|
if (error) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: 'Validation failed',
|
|
details: error.details.map((detail) => detail.message),
|
|
});
|
|
}
|
|
req.body = value;
|
|
next();
|
|
};
|
|
|
|
exports.validatePreviewTemplate = (req, res, next) => {
|
|
const { error, value } = previewSchema.validate(req.body, { abortEarly: false });
|
|
if (error) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: 'Validation failed',
|
|
details: error.details.map((detail) => detail.message),
|
|
});
|
|
}
|
|
req.body = value;
|
|
next();
|
|
};
|
|
|
|
|