forked from UKSOURCE/cms.hailearning.edu.vn
feat: standardize admin form limits and guidance
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
const Pricing = require("../models/pricing");
|
||||
const {
|
||||
validateLengthRules,
|
||||
summarizeLengthErrors,
|
||||
} = require("../utils/lengthValidation");
|
||||
const {
|
||||
PRICING_LENGTH_RULES,
|
||||
} = require("../constants/contentLengthRules");
|
||||
const writeAuditLog = require("../audit/writeAuditLog");
|
||||
const diffObject = require("../audit/diffObject");
|
||||
const AUDIT_ACTIONS = require("../constants/auditAction");
|
||||
|
||||
const getLengthValidationMessage = (validation) =>
|
||||
summarizeLengthErrors(validation, 3) ||
|
||||
"One or more fields exceed the allowed length.";
|
||||
|
||||
// ==================== CMS ADMIN FUNCTIONS ====================
|
||||
|
||||
// Render admin page for pricing management
|
||||
@@ -86,6 +97,20 @@ exports.update = async (req, res) => {
|
||||
? JSON.parse(testimonials)
|
||||
: testimonials;
|
||||
|
||||
const validation = validateLengthRules(
|
||||
{
|
||||
hero: heroData,
|
||||
pricingSection: pricingSectionData,
|
||||
plans: plansData,
|
||||
testimonials: testimonialsData,
|
||||
},
|
||||
PRICING_LENGTH_RULES,
|
||||
);
|
||||
if (!validation.valid) {
|
||||
req.flash("error", getLengthValidationMessage(validation));
|
||||
return res.redirect("/admin/pricing");
|
||||
}
|
||||
|
||||
let pricing = await Pricing.findOne({ name: "default" });
|
||||
|
||||
// ✅ Capture BEFORE state
|
||||
|
||||
Reference in New Issue
Block a user