forked from UKSOURCE/cms.lams
Introduce a centralized system to manage all website form submissions and newsletter subscriptions. - Add `Submission` and `NewsletterSubscription` models with MongoDB schema validation - Implement `submissionController` and `newsletterSubscriptionController` for CRUD operations and filtering - Create a unified admin UI for reviewing submissions across different sources (home, request, contact, partnership, newsletter) - Add database migration scripts for creating collections and indexes - Refactor partnership inquiry forms to use a fixed field structure - Update admin navigation and server CORS settings to support PATCH requests
414 lines
12 KiB
JavaScript
414 lines
12 KiB
JavaScript
const express = require("express");
|
|
const router = express.Router();
|
|
const { ensureAuthenticated } = require("../middleware/auth");
|
|
const dashboardController = require("../controllers/dashboardController");
|
|
const uploadController = require("../controllers/uploadController");
|
|
|
|
const homeController = require("../controllers/homeController");
|
|
const headerController = require("../controllers/headerController");
|
|
const footerController = require("../controllers/footerController");
|
|
const aboutController = require("../controllers/aboutController");
|
|
|
|
const partnershipsController = require("../controllers/partnershipsController");
|
|
const historyPageController = require("../controllers/historyPageController");
|
|
const accreditationController = require("../controllers/accreditationController");
|
|
const admissionsController = require("../controllers/admissionsController");
|
|
const policiesController = require("../controllers/policiesController");
|
|
|
|
const formController = require("../controllers/formController");
|
|
const contactController = require("../controllers/contactController");
|
|
const studentSupportController = require("../controllers/studentSupportController");
|
|
const requestInfoController = require("../controllers/requestInfoController");
|
|
const submissionController = require("../controllers/submissionController");
|
|
const newsletterSubscriptionController = require("../controllers/newsletterSubscriptionController");
|
|
|
|
const pageController = require("../controllers/pageController");
|
|
const settingController = require("../controllers/settingController");
|
|
|
|
const { upload, uploadVideo, convertToWebp } = require("../middleware/upload");
|
|
|
|
const auditLogController = require("../controllers/auditLogController");
|
|
|
|
const headerMenuController = require("../controllers/headerMenuController");
|
|
const programmeController = require("../controllers/programmeController");
|
|
|
|
// Blog controllers
|
|
const blogController = require("../controllers/blogController");
|
|
const blogCategoryController = require("../controllers/blogCategoryController");
|
|
const blogTagController = require("../controllers/blogTagController");
|
|
|
|
// Dashboard
|
|
router.get("/dashboard", ensureAuthenticated, dashboardController.getDashboard);
|
|
|
|
// Home
|
|
router.get("/home", ensureAuthenticated, homeController.index);
|
|
router.post("/home/update", ensureAuthenticated, homeController.update);
|
|
// router.get("/home/api/blogs", ensureAuthenticated, homeController.apiGetBlogs);
|
|
|
|
// Middleware chuẩn hóa code
|
|
router.param("code", (req, res, next, code) => {
|
|
req.params.code = code.toUpperCase();
|
|
next();
|
|
});
|
|
|
|
// About
|
|
router.get("/about", ensureAuthenticated, aboutController.index);
|
|
router.post("/about/update", ensureAuthenticated, aboutController.update);
|
|
|
|
router.get("/partnerships", ensureAuthenticated, partnershipsController.index);
|
|
router.post(
|
|
"/partnerships/update",
|
|
ensureAuthenticated,
|
|
partnershipsController.update,
|
|
);
|
|
router.get("/history", ensureAuthenticated, historyPageController.index);
|
|
router.post("/history/update", ensureAuthenticated, historyPageController.update);
|
|
router.get(
|
|
"/accreditation",
|
|
ensureAuthenticated,
|
|
accreditationController.index,
|
|
);
|
|
router.post(
|
|
"/accreditation/update",
|
|
ensureAuthenticated,
|
|
accreditationController.update,
|
|
);
|
|
router.get("/admissions", ensureAuthenticated, admissionsController.index);
|
|
router.get(
|
|
"/admissions/calculator/:optionId",
|
|
ensureAuthenticated,
|
|
admissionsController.editCalculatorOption,
|
|
);
|
|
router.post(
|
|
"/admissions/calculator/:optionId/update",
|
|
ensureAuthenticated,
|
|
admissionsController.updateCalculatorOption,
|
|
);
|
|
router.post(
|
|
"/admissions/update",
|
|
ensureAuthenticated,
|
|
admissionsController.update,
|
|
);
|
|
router.get("/policies", ensureAuthenticated, policiesController.index);
|
|
router.post("/policies/update", ensureAuthenticated, policiesController.update);
|
|
router.get(
|
|
"/policies/:policyId/section",
|
|
ensureAuthenticated,
|
|
policiesController.editSections,
|
|
);
|
|
router.post(
|
|
"/policies/:policyId/section/update",
|
|
ensureAuthenticated,
|
|
policiesController.updateSections,
|
|
);
|
|
|
|
// Booking admin CRUD removed
|
|
|
|
// Form Management
|
|
router.get("/form", ensureAuthenticated, formController.index);
|
|
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,
|
|
});
|
|
});
|
|
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.get("/header/data", ensureAuthenticated, headerController.api); // Normalized from getHeaderData
|
|
router.patch(
|
|
"/header/:id/status",
|
|
ensureAuthenticated,
|
|
headerController.updateStatus,
|
|
);
|
|
router.delete("/header/:id", ensureAuthenticated, headerController.destroy);
|
|
|
|
// Header Menu INTEGRATED routes
|
|
router.post(
|
|
"/header/menu/create",
|
|
ensureAuthenticated,
|
|
headerMenuController.store,
|
|
);
|
|
router.post(
|
|
"/header/menu/update/:id",
|
|
ensureAuthenticated,
|
|
headerMenuController.update,
|
|
);
|
|
router.post(
|
|
"/header/menu/delete",
|
|
ensureAuthenticated,
|
|
headerMenuController.destroy,
|
|
);
|
|
router.post(
|
|
"/header/menu/reorder",
|
|
ensureAuthenticated,
|
|
headerMenuController.reorder,
|
|
);
|
|
|
|
// Footer routes
|
|
router.get("/footer", ensureAuthenticated, footerController.index);
|
|
router.post("/footer/update", ensureAuthenticated, footerController.update);
|
|
|
|
// Contact routes
|
|
router.get("/contact", ensureAuthenticated, contactController.index);
|
|
router.post("/contact/update", ensureAuthenticated, contactController.update);
|
|
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,
|
|
);
|
|
|
|
// Unified submission management
|
|
router.get("/submissions", ensureAuthenticated, submissionController.index);
|
|
router.get("/submissions/data", ensureAuthenticated, submissionController.list);
|
|
router.get("/submissions/:id", ensureAuthenticated, submissionController.detail);
|
|
router.patch("/submissions/:id", ensureAuthenticated, submissionController.update);
|
|
router.get(
|
|
"/newsletter-subscriptions/data",
|
|
ensureAuthenticated,
|
|
newsletterSubscriptionController.list,
|
|
);
|
|
router.get(
|
|
"/newsletter-subscriptions/:id",
|
|
ensureAuthenticated,
|
|
newsletterSubscriptionController.detail,
|
|
);
|
|
router.patch(
|
|
"/newsletter-subscriptions/:id",
|
|
ensureAuthenticated,
|
|
newsletterSubscriptionController.update,
|
|
);
|
|
|
|
// Student Support (LAMS static page)
|
|
router.get(
|
|
"/student-support",
|
|
ensureAuthenticated,
|
|
studentSupportController.index,
|
|
);
|
|
router.post(
|
|
"/student-support/update",
|
|
ensureAuthenticated,
|
|
studentSupportController.update,
|
|
);
|
|
|
|
// Request Info (LAMS static page)
|
|
router.get(
|
|
"/request-info",
|
|
ensureAuthenticated,
|
|
requestInfoController.index,
|
|
);
|
|
router.post(
|
|
"/request-info/update",
|
|
ensureAuthenticated,
|
|
requestInfoController.update,
|
|
);
|
|
|
|
// 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");
|
|
|
|
// 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)),
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// 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,
|
|
});
|
|
});
|
|
|
|
|
|
// Programme Management
|
|
router.get("/programme", ensureAuthenticated, programmeController.index);
|
|
router.get("/programme/edit/:id", ensureAuthenticated, programmeController.edit);
|
|
router.post("/programme/update/:id", ensureAuthenticated, upload.single('heroImage'), programmeController.update);
|
|
router.post("/programme/delete/:id", ensureAuthenticated, programmeController.delete);
|
|
|
|
// Blog routes
|
|
// Blog Management Routes
|
|
router.get("/blog", ensureAuthenticated, blogController.index);
|
|
router.get("/blog/create", ensureAuthenticated, blogController.create);
|
|
router.post("/blog/create", ensureAuthenticated, blogController.store);
|
|
router.get("/blog/:id/edit", ensureAuthenticated, blogController.edit);
|
|
router.post("/blog/:id/edit", ensureAuthenticated, blogController.update);
|
|
router.post("/blog/:id/delete", ensureAuthenticated, blogController.destroy);
|
|
|
|
// Comment management routes
|
|
router.post(
|
|
"/blog/:blogId/comments/:commentId/approve",
|
|
ensureAuthenticated,
|
|
blogController.approveComment,
|
|
);
|
|
router.post(
|
|
"/blog/:blogId/comments/:commentId/reject",
|
|
ensureAuthenticated,
|
|
blogController.rejectComment,
|
|
);
|
|
router.post(
|
|
"/blog/:blogId/comments/:commentId/delete",
|
|
ensureAuthenticated,
|
|
blogController.deleteComment,
|
|
);
|
|
|
|
// Blog Categories Management
|
|
router.get(
|
|
"/blog/categories",
|
|
ensureAuthenticated,
|
|
blogCategoryController.index,
|
|
);
|
|
router.get(
|
|
"/blog/categories/create",
|
|
ensureAuthenticated,
|
|
blogCategoryController.create,
|
|
);
|
|
router.post(
|
|
"/blog/categories/create",
|
|
ensureAuthenticated,
|
|
blogCategoryController.store,
|
|
);
|
|
router.get(
|
|
"/blog/categories/:id/edit",
|
|
ensureAuthenticated,
|
|
blogCategoryController.edit,
|
|
);
|
|
router.post(
|
|
"/blog/categories/:id/edit",
|
|
ensureAuthenticated,
|
|
blogCategoryController.update,
|
|
);
|
|
router.post(
|
|
"/blog/categories/:id/delete",
|
|
ensureAuthenticated,
|
|
blogCategoryController.destroy,
|
|
);
|
|
router.post(
|
|
"/blog/categories/quick-create",
|
|
ensureAuthenticated,
|
|
blogCategoryController.quickCreate,
|
|
);
|
|
|
|
// Blog Tags Management
|
|
router.get("/blog/tags", ensureAuthenticated, blogTagController.index);
|
|
router.get("/blog/tags/create", ensureAuthenticated, blogTagController.create);
|
|
router.post("/blog/tags/create", ensureAuthenticated, blogTagController.store);
|
|
router.get("/blog/tags/:id/edit", ensureAuthenticated, blogTagController.edit);
|
|
router.post(
|
|
"/blog/tags/:id/edit",
|
|
ensureAuthenticated,
|
|
blogTagController.update,
|
|
);
|
|
router.post(
|
|
"/blog/tags/:id/delete",
|
|
ensureAuthenticated,
|
|
blogTagController.destroy,
|
|
);
|
|
router.post(
|
|
"/blog/tags/quick-create",
|
|
ensureAuthenticated,
|
|
blogTagController.quickCreate,
|
|
);
|
|
|
|
// Audit Log routes
|
|
router.get("/audit-logs", ensureAuthenticated, auditLogController.index);
|
|
router.get("/audit-logs/:id", ensureAuthenticated, auditLogController.show);
|
|
router.get("/audit-logs-api", ensureAuthenticated, auditLogController.api);
|
|
router.post(
|
|
"/audit-logs/cleanup",
|
|
ensureAuthenticated,
|
|
auditLogController.cleanup,
|
|
);
|
|
|
|
module.exports = router;
|