feat: Mail template management UI and API CRUD
- 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)
This commit is contained in:
63
backend/src/validators/template.validator.js
Normal file
63
backend/src/validators/template.validator.js
Normal file
@@ -0,0 +1,63 @@
|
||||
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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user