feat(header): add admin UI and APIs for header management

This commit is contained in:
2026-02-04 10:06:22 +07:00
parent 00f93cefab
commit befe6b30aa
12 changed files with 2359 additions and 1622 deletions

View File

@@ -39,8 +39,8 @@ router.post("/home/update", ensureAuthenticated, homeController.update);
// Middleware chuẩn hóa code
router.param("code", (req, res, next, code) => {
req.params.code = code.toUpperCase();
next();
req.params.code = code.toUpperCase();
next();
});
// About
@@ -49,99 +49,42 @@ router.post("/about/update", ensureAuthenticated, aboutController.update);
// AboutUs admin CRUD
router.get("/about-us", ensureAuthenticated, aboutUsController.index);
router.get(
"/about-us/create",
ensureAuthenticated,
aboutUsController.createForm,
);
router.get("/about-us/create", ensureAuthenticated, aboutUsController.createForm);
router.post("/about-us/create", ensureAuthenticated, aboutUsController.create);
router.get(
"/about-us/:id/edit",
ensureAuthenticated,
aboutUsController.editForm,
);
router.post(
"/about-us/:id/update",
ensureAuthenticated,
aboutUsController.update,
);
router.post(
"/about-us/:id/delete",
ensureAuthenticated,
aboutUsController.delete,
);
router.get(
"/about-us/:id/preview",
ensureAuthenticated,
aboutUsController.preview,
);
router.get("/about-us/:id/edit", ensureAuthenticated, aboutUsController.editForm);
router.post("/about-us/:id/update", ensureAuthenticated, aboutUsController.update);
router.post("/about-us/:id/delete", ensureAuthenticated, aboutUsController.delete);
router.get("/about-us/:id/preview", ensureAuthenticated, aboutUsController.preview);
// Booking admin CRUD removed
// Form Management
router.get("/form", ensureAuthenticated, formController.index);
router.post(
"/form/update",
ensureAuthenticated,
formController.updateDefaultForm,
);
router.post("/form/update", ensureAuthenticated, formController.updateDefaultForm);
// Upload routes
router.get("/upload", ensureAuthenticated, (req, res) => {
res.render("admin/upload/index", {
layout: "layouts/admin",
title: "Quản lý Upload Ảnh",
user: req.session.user,
});
res.render("admin/upload/index", {
layout: "layouts/admin",
title: "Quản lý Upload Ảnh",
user: req.session.user,
});
});
router.post(
"/upload/image",
ensureAuthenticated,
upload.single("image"),
// convertToWebp, // Disabled to keep original image format (JPG/PNG)
uploadController.uploadImage,
);
router.post(
"/upload/video",
ensureAuthenticated,
uploadVideo.single("video"),
uploadController.uploadVideo,
);
router.post(
"/upload/update-path",
ensureAuthenticated,
uploadController.updateImagePath,
);
router.post(
"/upload/delete",
ensureAuthenticated,
uploadController.deleteImage,
);
router.post("/upload/image", ensureAuthenticated, upload.single("image"), uploadController.uploadImage);
router.post("/upload/video", ensureAuthenticated, uploadVideo.single("video"), uploadController.uploadVideo);
router.post("/upload/update-path", ensureAuthenticated, uploadController.updateImagePath);
router.post("/upload/delete", ensureAuthenticated, uploadController.deleteImage);
// Header routes
router.get("/header", ensureAuthenticated, headerController.index);
router.post("/header/update", ensureAuthenticated, headerController.update);
router.post(
"/header/update-menu",
ensureAuthenticated,
headerController.updateMenu,
);
router.get(
"/header/menu-tree",
ensureAuthenticated,
headerController.getMenuTree,
);
router.get(
"/header/programmes/:menuId",
ensureAuthenticated,
headerController.getProgrammesByMenuId,
);
router.get(
"/header/menu-item/:menuId",
ensureAuthenticated,
headerController.getMenuItem,
);
router.post("/header/update-menu", ensureAuthenticated, headerController.updateMenu);
router.get("/header/menu-tree", ensureAuthenticated, headerController.getMenuTree);
router.get("/header/programmes/:menuId", ensureAuthenticated, headerController.getProgrammesByMenuId);
router.get("/header/menu-item/:menuId", ensureAuthenticated, headerController.getMenuItem);
router.get("/header/data", ensureAuthenticated, headerController.getHeaderData);
router.patch("/header/:id/status", ensureAuthenticated, headerController.updateStatus);
router.delete("/header/:id", ensureAuthenticated, headerController.destroy);
// Footer routes
router.get("/footer", ensureAuthenticated, footerController.index);
@@ -151,160 +94,60 @@ router.get("/footer/data", ensureAuthenticated, footerController.getFooterData);
// Contact routes
router.get("/contact", ensureAuthenticated, contactController.index);
router.post("/contact/update", ensureAuthenticated, contactController.update);
router.get(
"/contact/data",
ensureAuthenticated,
contactController.getContactData,
);
router.get("/contact/data", ensureAuthenticated, contactController.getContactData);
// Contact submissions management
router.get(
"/contact/submissions",
ensureAuthenticated,
contactController.getSubmissions,
);
router.put(
"/contact/submissions/:id",
ensureAuthenticated,
contactController.updateSubmissionStatus,
);
router.get("/contact/submissions", ensureAuthenticated, contactController.getSubmissions);
router.put("/contact/submissions/:id", ensureAuthenticated, contactController.updateSubmissionStatus);
// Appointment management
const appointmentController = require("../controllers/appointmentController");
router.get(
"/appointments",
ensureAuthenticated,
appointmentController.getAppointments,
);
router.get(
"/appointments/:id",
ensureAuthenticated,
appointmentController.getAppointmentById,
);
router.put(
"/appointments/:id",
ensureAuthenticated,
appointmentController.updateAppointmentStatus,
);
router.delete(
"/appointments/:id",
ensureAuthenticated,
appointmentController.deleteAppointment,
);
router.get("/appointments", ensureAuthenticated, appointmentController.getAppointments);
router.get("/appointments/:id", ensureAuthenticated, appointmentController.getAppointmentById);
router.put("/appointments/:id", ensureAuthenticated, appointmentController.updateAppointmentStatus);
router.delete("/appointments/:id", ensureAuthenticated, appointmentController.deleteAppointment);
// Appointment CMS page management
router.get("/appointment", ensureAuthenticated, appointmentController.index);
router.post(
"/appointment/update",
ensureAuthenticated,
appointmentController.update,
);
router.get(
"/appointment/data",
ensureAuthenticated,
appointmentController.getAppointmentData,
);
router.post("/appointment/update", ensureAuthenticated, appointmentController.update);
router.get("/appointment/data", ensureAuthenticated, appointmentController.getAppointmentData);
// Pricing CMS page management
const pricingController = require("../controllers/pricingController");
router.get("/pricing", ensureAuthenticated, pricingController.index);
router.post("/pricing/update", ensureAuthenticated, pricingController.update);
router.get(
"/pricing/data",
ensureAuthenticated,
pricingController.getPricingData,
);
router.get("/pricing/data", ensureAuthenticated, pricingController.getPricingData);
// Activity CRUD routes
router.get("/activity", ensureAuthenticated, activityController.index);
router.get(
"/activity/create",
ensureAuthenticated,
activityController.createForm,
);
router.get("/activity/create", ensureAuthenticated, activityController.createForm);
router.post("/activity/create", ensureAuthenticated, activityController.create);
// Update filters (place before any parameterized /activity/:id routes to avoid route collision)
router.post(
"/activity/filters/update",
ensureAuthenticated,
activityController.updateFilters,
);
router.post("/activity/filters/update", ensureAuthenticated, activityController.updateFilters);
// Update hero (global hero section for activities)
router.post(
"/activity/hero/update",
ensureAuthenticated,
activityController.updateHero,
);
router.get(
"/activity/:id/edit",
ensureAuthenticated,
activityController.editForm,
);
router.post(
"/activity/:id/update",
ensureAuthenticated,
activityController.update,
);
router.post(
"/activity/:id/delete",
ensureAuthenticated,
activityController.delete,
);
router.post(
"/activity/:id/toggle-status",
ensureAuthenticated,
activityController.toggleStatus,
);
router.post("/activity/hero/update", ensureAuthenticated, activityController.updateHero);
router.get("/activity/:id/edit", ensureAuthenticated, activityController.editForm);
router.post("/activity/:id/update", ensureAuthenticated, activityController.update);
router.post("/activity/:id/delete", ensureAuthenticated, activityController.delete);
router.post("/activity/:id/toggle-status", ensureAuthenticated, activityController.toggleStatus);
// Update display order
router.post(
"/activity/update-order",
ensureAuthenticated,
activityController.updateOrder,
);
router.post("/activity/update-order", ensureAuthenticated, activityController.updateOrder);
// Booking submissions routes
router.get(
"/activity/:id/bookings/count",
ensureAuthenticated,
activityController.getBookingCount,
);
router.get(
"/activity/:id/bookings",
ensureAuthenticated,
activityController.getBookingSubmissions,
);
router.get(
"/activity/:id/bookings/export",
ensureAuthenticated,
activityController.exportBookingData,
);
router.get("/activity/:id/bookings/count", ensureAuthenticated, activityController.getBookingCount);
router.get("/activity/:id/bookings", ensureAuthenticated, activityController.getBookingSubmissions);
router.get("/activity/:id/bookings/export", ensureAuthenticated, activityController.exportBookingData);
// Export all bookings (across all activities)
router.get(
"/bookings/export-all",
ensureAuthenticated,
activityController.exportAllBookingsData,
);
router.get("/bookings/export-all", ensureAuthenticated, activityController.exportAllBookingsData);
// Update booking submission
router.put(
"/bookings/:bookingId",
ensureAuthenticated,
bookingSubmissionController.updateBookingSubmission,
);
router.put("/bookings/:bookingId", ensureAuthenticated, bookingSubmissionController.updateBookingSubmission);
// Delete booking submission
router.delete(
"/bookings/:bookingId",
ensureAuthenticated,
bookingSubmissionController.deleteBookingSubmission,
);
router.delete("/bookings/:bookingId", ensureAuthenticated, bookingSubmissionController.deleteBookingSubmission);
// Update filters
// Preview activity
router.get(
"/activity/:id/preview",
ensureAuthenticated,
activityController.preview,
);
router.get("/activity/:id/preview", ensureAuthenticated, activityController.preview);
// FAQ routes - Thêm vào đây
router.get("/faq", ensureAuthenticated, faqController.index);
@@ -413,65 +256,61 @@ router.post(
// Test Image Paths route
router.get("/test-images", ensureAuthenticated, (req, res) => {
const fs = require("fs");
const path = require("path");
const campLocationData = require("../data/camp-location.json");
const fs = require("fs");
const path = require("path");
const campLocationData = require("../data/camp-location.json");
// Collect all image paths
const imagePaths = [];
// Collect all image paths
const imagePaths = [];
// Camps images
if (campLocationData.camps) {
campLocationData.camps.forEach((camp) => {
if (camp.image) {
imagePaths.push({
type: "Camp",
name: camp.title,
path: camp.image,
exists: fs.existsSync(path.join(__dirname, "../public", camp.image)),
// Camps images
if (campLocationData.camps) {
campLocationData.camps.forEach((camp) => {
if (camp.image) {
imagePaths.push({
type: "Camp",
name: camp.title,
path: camp.image,
exists: fs.existsSync(path.join(__dirname, "../public", camp.image)),
});
}
});
}
}
// Locations images
if (campLocationData.locations) {
campLocationData.locations.forEach((location) => {
if (location.imageSrc) {
imagePaths.push({
type: "Location",
name: location.title,
path: location.imageSrc,
exists: fs.existsSync(path.join(__dirname, "../public", location.imageSrc)),
});
}
// Program images
if (location.programOptions) {
location.programOptions.forEach((program) => {
if (program.imageSrc) {
imagePaths.push({
type: "Program",
name: program.title,
path: program.imageSrc,
exists: fs.existsSync(path.join(__dirname, "../public", program.imageSrc)),
});
}
});
}
});
}
res.render("admin/test-images", {
layout: "layouts/admin",
title: "Test Image Paths",
images: imagePaths,
user: req.session.user,
});
}
// Locations images
if (campLocationData.locations) {
campLocationData.locations.forEach((location) => {
if (location.imageSrc) {
imagePaths.push({
type: "Location",
name: location.title,
path: location.imageSrc,
exists: fs.existsSync(
path.join(__dirname, "../public", location.imageSrc),
),
});
}
// Program images
if (location.programOptions) {
location.programOptions.forEach((program) => {
if (program.imageSrc) {
imagePaths.push({
type: "Program",
name: program.title,
path: program.imageSrc,
exists: fs.existsSync(
path.join(__dirname, "../public", program.imageSrc),
),
});
}
});
}
});
}
res.render("admin/test-images", {
layout: "layouts/admin",
title: "Test Image Paths",
images: imagePaths,
user: req.session.user,
});
});
// Display visa management page

View File

@@ -5,6 +5,7 @@ const homeController = require("../controllers/homeController");
const aboutController = require("../controllers/aboutController");
const aboutUsController = require("../controllers/aboutUsController");
const headerController = require("../controllers/headerController");
const socialLinkController = require("../controllers/socialLinkController");
const footerController = require("../controllers/footerController");
const contactController = require("../controllers/contactController");
const faqController = require("../controllers/faqController");
@@ -27,10 +28,10 @@ const blogTagController = require("../controllers/blogTagController");
// Trang chủ
router.get("/", (req, res) => {
res.render("index", {
title: "Welcome",
layout: "layouts/main",
});
res.render("index", {
title: "Welcome",
layout: "layouts/main",
});
});
// API để lấy dữ liệu trang chủ
@@ -50,6 +51,14 @@ router.get("/api/header", headerController.api);
// Menu Tree API route (for frontend)
router.get("/api/menu-tree", headerController.getMenuTreeAPI);
// Social Links API routes
router.get("/api/social-links", socialLinkController.getAll);
router.get("/api/social-links/:platform", socialLinkController.show);
router.post("/api/social-links", socialLinkController.store);
router.put("/api/social-links/:platform", socialLinkController.update);
router.delete("/api/social-links/:platform", socialLinkController.destroy);
router.post("/api/social-links/bulk-update", socialLinkController.bulkUpdate);
// Footer API route
router.get("/api/footer", footerController.api);
@@ -85,69 +94,57 @@ router.get("/api/terms", termsController.api);
// Travel public page and API
router.get("/travel", async (req, res) => {
try {
const Travel = require("../models/travel");
const travel = await Travel.findOne();
try {
const Travel = require("../models/travel");
const travel = await Travel.findOne();
if (!travel) {
return res.status(404).render("errors/404", {
title: "Page Not Found",
message: "Travel information not found",
});
if (!travel) {
return res.status(404).render("errors/404", {
title: "Page Not Found",
message: "Travel information not found",
});
}
res.render("page/travel", {
title: travel.page.title,
data: travel.toObject(),
});
} catch (error) {
console.error("Error loading travel page:", error);
res.status(500).render("errors/500", {
title: "Server Error",
message: "Error loading travel page",
});
}
res.render("page/travel", {
title: travel.page.title,
data: travel.toObject(),
});
} catch (error) {
console.error("Error loading travel page:", error);
res.status(500).render("errors/500", {
title: "Server Error",
message: "Error loading travel page",
});
}
});
router.get("/api/travel", travelController.api);
// Booking submission APIs (public endpoints)
router.post("/api/booking/submit", bookingSubmissionController.submitBooking);
router.get("/api/activity/:activityId/sessions", bookingSubmissionController.getAvailableSessions);
router.get(
"/api/activity/:activityId/sessions",
bookingSubmissionController.getAvailableSessions,
);
router.get(
"/api/activity/:activityId/session/:sessionId/availability",
bookingSubmissionController.getSessionAvailability,
"/api/activity/:activityId/session/:sessionId/availability",
bookingSubmissionController.getSessionAvailability,
);
// New API for creating bookings directly into camp sessions (by program)
router.post(
"/api/camps/:program/sessions/:sessionId/bookings",
activityController.createSessionBookingByProgram,
);
router.get(
"/api/camps/:program/sessions/:sessionId/bookings",
activityController.getSessionBookingsByProgram,
);
router.post("/api/camps/:program/sessions/:sessionId/bookings", activityController.createSessionBookingByProgram);
router.get("/api/camps/:program/sessions/:sessionId/bookings", activityController.getSessionBookingsByProgram);
// Keep admin-style update/delete by activityId (protected) if needed
router.put(
"/api/camps/:activityId/sessions/:sessionId/bookings/:bookingId",
activityController.updateSessionBooking,
);
router.put("/api/camps/:activityId/sessions/:sessionId/bookings/:bookingId", activityController.updateSessionBooking);
router.delete(
"/api/camps/:activityId/sessions/:sessionId/bookings/:bookingId",
activityController.deleteSessionBooking,
"/api/camps/:activityId/sessions/:sessionId/bookings/:bookingId",
activityController.deleteSessionBooking,
);
// Demo booking form
router.get("/demo/booking-form", (req, res) => {
res.sendFile(path.join(__dirname, "../views/demo/booking-form.html"));
res.sendFile(path.join(__dirname, "../views/demo/booking-form.html"));
});
// Demo session booking API
router.get("/demo/session-booking-api", (req, res) => {
res.sendFile(path.join(__dirname, "../views/demo/session-booking-api.html"));
res.sendFile(path.join(__dirname, "../views/demo/session-booking-api.html"));
});
// Blog API Routes