forked from UKSOURCE/cms.hailearning.edu.vn
feat: standardize admin form limits and guidance
This commit is contained in:
@@ -2,6 +2,17 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { addBaseUrlToImages } = require("../utils/imageHelper");
|
||||
const Booking = require("../models/booking");
|
||||
const {
|
||||
validateLengthRules,
|
||||
summarizeLengthErrors,
|
||||
} = require("../utils/lengthValidation");
|
||||
const {
|
||||
BOOKING_LENGTH_RULES,
|
||||
} = require("../constants/contentLengthRules");
|
||||
|
||||
const getBookingLengthMessage = (validation) =>
|
||||
summarizeLengthErrors(validation, 3) ||
|
||||
"One or more fields exceed the allowed length.";
|
||||
|
||||
// -------------------- Public helpers --------------------
|
||||
const getBookingData = async () => {
|
||||
@@ -398,6 +409,12 @@ exports.update = async (req, res) => {
|
||||
return req.session.save(() => res.redirect("/admin/booking"));
|
||||
}
|
||||
|
||||
const lengthValidation = validateLengthRules(updateData, BOOKING_LENGTH_RULES);
|
||||
if (!lengthValidation.valid) {
|
||||
req.flash("error_msg", getBookingLengthMessage(lengthValidation));
|
||||
return req.session.save(() => res.redirect("/admin/booking"));
|
||||
}
|
||||
|
||||
// Validate data structure
|
||||
const validation = validateBookingData(updateData);
|
||||
if (!validation.isValid) {
|
||||
@@ -546,4 +563,4 @@ const getFinalBooking = (staticBooking, dbBooking) => {
|
||||
}
|
||||
|
||||
return merged;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user