forked from UKSOURCE/cms.hailearning.edu.vn
feat: add service management module with CRUD operations
This commit is contained in:
187
routes/admin.js
187
routes/admin.js
@@ -23,6 +23,7 @@ const insuranceController = require("../controllers/insuranceController");
|
||||
|
||||
const activityController = require("../controllers/activityController");
|
||||
const bookingSubmissionController = require("../controllers/bookingSubmissionController");
|
||||
const serviceController = require("../controllers/serviceController");
|
||||
|
||||
// Dashboard
|
||||
router.get("/dashboard", ensureAuthenticated, dashboardController.getDashboard);
|
||||
@@ -46,28 +47,28 @@ router.get("/about-us", ensureAuthenticated, aboutUsController.index);
|
||||
router.get(
|
||||
"/about-us/create",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.createForm
|
||||
aboutUsController.createForm,
|
||||
);
|
||||
router.post("/about-us/create", ensureAuthenticated, aboutUsController.create);
|
||||
router.get(
|
||||
"/about-us/:id/edit",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.editForm
|
||||
aboutUsController.editForm,
|
||||
);
|
||||
router.post(
|
||||
"/about-us/:id/update",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.update
|
||||
aboutUsController.update,
|
||||
);
|
||||
router.post(
|
||||
"/about-us/:id/delete",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.delete
|
||||
aboutUsController.delete,
|
||||
);
|
||||
router.get(
|
||||
"/about-us/:id/preview",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.preview
|
||||
aboutUsController.preview,
|
||||
);
|
||||
|
||||
// Booking admin CRUD removed
|
||||
@@ -77,7 +78,7 @@ router.get("/form", ensureAuthenticated, formController.index);
|
||||
router.post(
|
||||
"/form/update",
|
||||
ensureAuthenticated,
|
||||
formController.updateDefaultForm
|
||||
formController.updateDefaultForm,
|
||||
);
|
||||
|
||||
// Upload routes
|
||||
@@ -93,23 +94,23 @@ router.post(
|
||||
ensureAuthenticated,
|
||||
upload.single("image"),
|
||||
// convertToWebp, // Disabled to keep original image format (JPG/PNG)
|
||||
uploadController.uploadImage
|
||||
uploadController.uploadImage,
|
||||
);
|
||||
router.post(
|
||||
"/upload/video",
|
||||
ensureAuthenticated,
|
||||
uploadVideo.single("video"),
|
||||
uploadController.uploadVideo
|
||||
uploadController.uploadVideo,
|
||||
);
|
||||
router.post(
|
||||
"/upload/update-path",
|
||||
ensureAuthenticated,
|
||||
uploadController.updateImagePath
|
||||
uploadController.updateImagePath,
|
||||
);
|
||||
router.post(
|
||||
"/upload/delete",
|
||||
ensureAuthenticated,
|
||||
uploadController.deleteImage
|
||||
uploadController.deleteImage,
|
||||
);
|
||||
|
||||
// Header routes
|
||||
@@ -118,22 +119,22 @@ router.post("/header/update", ensureAuthenticated, headerController.update);
|
||||
router.post(
|
||||
"/header/update-menu",
|
||||
ensureAuthenticated,
|
||||
headerController.updateMenu
|
||||
headerController.updateMenu,
|
||||
);
|
||||
router.get(
|
||||
"/header/menu-tree",
|
||||
ensureAuthenticated,
|
||||
headerController.getMenuTree
|
||||
headerController.getMenuTree,
|
||||
);
|
||||
router.get(
|
||||
"/header/programmes/:menuId",
|
||||
ensureAuthenticated,
|
||||
headerController.getProgrammesByMenuId
|
||||
headerController.getProgrammesByMenuId,
|
||||
);
|
||||
router.get(
|
||||
"/header/menu-item/:menuId",
|
||||
ensureAuthenticated,
|
||||
headerController.getMenuItem
|
||||
headerController.getMenuItem,
|
||||
);
|
||||
router.get("/header/data", ensureAuthenticated, headerController.getHeaderData);
|
||||
|
||||
@@ -148,7 +149,7 @@ router.post("/contact/update", ensureAuthenticated, contactController.update);
|
||||
router.get(
|
||||
"/contact/data",
|
||||
ensureAuthenticated,
|
||||
contactController.getContactData
|
||||
contactController.getContactData,
|
||||
);
|
||||
|
||||
// Activity CRUD routes
|
||||
@@ -156,81 +157,81 @@ router.get("/activity", ensureAuthenticated, activityController.index);
|
||||
router.get(
|
||||
"/activity/create",
|
||||
ensureAuthenticated,
|
||||
activityController.createForm
|
||||
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
|
||||
activityController.updateFilters,
|
||||
);
|
||||
// Update hero (global hero section for activities)
|
||||
router.post(
|
||||
"/activity/hero/update",
|
||||
ensureAuthenticated,
|
||||
activityController.updateHero
|
||||
activityController.updateHero,
|
||||
);
|
||||
router.get(
|
||||
"/activity/:id/edit",
|
||||
ensureAuthenticated,
|
||||
activityController.editForm
|
||||
activityController.editForm,
|
||||
);
|
||||
router.post(
|
||||
"/activity/:id/update",
|
||||
ensureAuthenticated,
|
||||
activityController.update
|
||||
activityController.update,
|
||||
);
|
||||
router.post(
|
||||
"/activity/:id/delete",
|
||||
ensureAuthenticated,
|
||||
activityController.delete
|
||||
activityController.delete,
|
||||
);
|
||||
router.post(
|
||||
"/activity/:id/toggle-status",
|
||||
ensureAuthenticated,
|
||||
activityController.toggleStatus
|
||||
activityController.toggleStatus,
|
||||
);
|
||||
// Update display order
|
||||
router.post(
|
||||
"/activity/update-order",
|
||||
ensureAuthenticated,
|
||||
activityController.updateOrder
|
||||
activityController.updateOrder,
|
||||
);
|
||||
|
||||
// Booking submissions routes
|
||||
router.get(
|
||||
"/activity/:id/bookings/count",
|
||||
ensureAuthenticated,
|
||||
activityController.getBookingCount
|
||||
activityController.getBookingCount,
|
||||
);
|
||||
router.get(
|
||||
"/activity/:id/bookings",
|
||||
ensureAuthenticated,
|
||||
activityController.getBookingSubmissions
|
||||
activityController.getBookingSubmissions,
|
||||
);
|
||||
router.get(
|
||||
"/activity/:id/bookings/export",
|
||||
ensureAuthenticated,
|
||||
activityController.exportBookingData
|
||||
activityController.exportBookingData,
|
||||
);
|
||||
// Export all bookings (across all activities)
|
||||
router.get(
|
||||
"/bookings/export-all",
|
||||
ensureAuthenticated,
|
||||
activityController.exportAllBookingsData
|
||||
activityController.exportAllBookingsData,
|
||||
);
|
||||
// Update booking submission
|
||||
router.put(
|
||||
"/bookings/:bookingId",
|
||||
ensureAuthenticated,
|
||||
bookingSubmissionController.updateBookingSubmission
|
||||
bookingSubmissionController.updateBookingSubmission,
|
||||
);
|
||||
// Delete booking submission
|
||||
router.delete(
|
||||
"/bookings/:bookingId",
|
||||
ensureAuthenticated,
|
||||
bookingSubmissionController.deleteBookingSubmission
|
||||
bookingSubmissionController.deleteBookingSubmission,
|
||||
);
|
||||
|
||||
// Update filters
|
||||
@@ -239,7 +240,7 @@ router.delete(
|
||||
router.get(
|
||||
"/activity/:id/preview",
|
||||
ensureAuthenticated,
|
||||
activityController.preview
|
||||
activityController.preview,
|
||||
);
|
||||
|
||||
// FAQ routes - Thêm vào đây
|
||||
@@ -250,8 +251,16 @@ router.get("/faq/api", faqController.api);
|
||||
|
||||
// API routes cho quản lý FAQ items (AJAX calls)
|
||||
router.post("/faq/api/add-faq", ensureAuthenticated, faqController.addFAQ);
|
||||
router.put("/faq/api/update-faq-item/:sectionId/:faqId", ensureAuthenticated, faqController.updateFAQItem);
|
||||
router.delete("/faq/api/delete-faq-item/:sectionId/:faqId", ensureAuthenticated, faqController.deleteFAQItem);
|
||||
router.put(
|
||||
"/faq/api/update-faq-item/:sectionId/:faqId",
|
||||
ensureAuthenticated,
|
||||
faqController.updateFAQItem,
|
||||
);
|
||||
router.delete(
|
||||
"/faq/api/delete-faq-item/:sectionId/:faqId",
|
||||
ensureAuthenticated,
|
||||
faqController.deleteFAQItem,
|
||||
);
|
||||
router.get("/terms-conditions", ensureAuthenticated, termsController.index);
|
||||
router.post("/terms/update", ensureAuthenticated, termsController.update);
|
||||
router.get("/terms/data", ensureAuthenticated, termsController.getTermsData);
|
||||
@@ -267,80 +276,138 @@ router.get("/travel/api", travelController.api);
|
||||
router.get("/travel/seed", ensureAuthenticated, travelController.seed);
|
||||
|
||||
// API routes cho quản lý FAQ sections (AJAX calls)
|
||||
router.post("/faq/api/add-section", ensureAuthenticated, faqController.addFAQSection);
|
||||
router.put("/faq/api/update-section/:sectionId", ensureAuthenticated, faqController.updateFAQSection);
|
||||
router.delete("/faq/api/delete-section/:sectionId", ensureAuthenticated, faqController.deleteFAQSection);
|
||||
router.post("/faq/api/reorder-sections", ensureAuthenticated, faqController.reorderFAQSection);
|
||||
router.post(
|
||||
"/faq/api/add-section",
|
||||
ensureAuthenticated,
|
||||
faqController.addFAQSection,
|
||||
);
|
||||
router.put(
|
||||
"/faq/api/update-section/:sectionId",
|
||||
ensureAuthenticated,
|
||||
faqController.updateFAQSection,
|
||||
);
|
||||
router.delete(
|
||||
"/faq/api/delete-section/:sectionId",
|
||||
ensureAuthenticated,
|
||||
faqController.deleteFAQSection,
|
||||
);
|
||||
router.post(
|
||||
"/faq/api/reorder-sections",
|
||||
ensureAuthenticated,
|
||||
faqController.reorderFAQSection,
|
||||
);
|
||||
|
||||
// API routes cho sidebar navigation (AJAX calls)
|
||||
router.put("/faq/api/update-sidebar", ensureAuthenticated, faqController.updateSidebarNav);
|
||||
router.put(
|
||||
"/faq/api/update-sidebar",
|
||||
ensureAuthenticated,
|
||||
faqController.updateSidebarNav,
|
||||
);
|
||||
|
||||
// Safety routes
|
||||
router.get("/safety", ensureAuthenticated, safetyController.index);
|
||||
router.post("/safety/update", ensureAuthenticated, safetyController.update);
|
||||
// Camp Location routes
|
||||
router.get("/camp-location", ensureAuthenticated, campLocationController.index);
|
||||
router.post("/camp-location/update", ensureAuthenticated, campLocationController.update);
|
||||
router.post(
|
||||
"/camp-location/update",
|
||||
ensureAuthenticated,
|
||||
campLocationController.update,
|
||||
);
|
||||
|
||||
//Insurance routes
|
||||
router.get("/insurance", ensureAuthenticated, insuranceController.index);
|
||||
router.post("/insurance/update", ensureAuthenticated, insuranceController.update);
|
||||
router.post(
|
||||
"/insurance/update",
|
||||
ensureAuthenticated,
|
||||
insuranceController.update,
|
||||
);
|
||||
|
||||
// Service routes
|
||||
router.get("/service", ensureAuthenticated, serviceController.index);
|
||||
router.post("/service/update", ensureAuthenticated, serviceController.update);
|
||||
router.post(
|
||||
"/service/generate-slug",
|
||||
ensureAuthenticated,
|
||||
serviceController.generateSlug,
|
||||
);
|
||||
router.get("/service/:slug/edit", ensureAuthenticated, serviceController.edit);
|
||||
router.post(
|
||||
"/service/:slug/edit",
|
||||
ensureAuthenticated,
|
||||
serviceController.updateService,
|
||||
);
|
||||
router.get(
|
||||
"/service/:slug/details",
|
||||
ensureAuthenticated,
|
||||
serviceController.details,
|
||||
);
|
||||
router.post(
|
||||
"/service/:slug/details/update",
|
||||
ensureAuthenticated,
|
||||
serviceController.updateDetails,
|
||||
);
|
||||
|
||||
// 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 = [];
|
||||
|
||||
|
||||
// Camps images
|
||||
if (campLocationData.camps) {
|
||||
campLocationData.camps.forEach(camp => {
|
||||
campLocationData.camps.forEach((camp) => {
|
||||
if (camp.image) {
|
||||
imagePaths.push({
|
||||
type: 'Camp',
|
||||
type: "Camp",
|
||||
name: camp.title,
|
||||
path: camp.image,
|
||||
exists: fs.existsSync(path.join(__dirname, '../public', camp.image))
|
||||
exists: fs.existsSync(path.join(__dirname, "../public", camp.image)),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Locations images
|
||||
if (campLocationData.locations) {
|
||||
campLocationData.locations.forEach(location => {
|
||||
campLocationData.locations.forEach((location) => {
|
||||
if (location.imageSrc) {
|
||||
imagePaths.push({
|
||||
type: 'Location',
|
||||
type: "Location",
|
||||
name: location.title,
|
||||
path: location.imageSrc,
|
||||
exists: fs.existsSync(path.join(__dirname, '../public', location.imageSrc))
|
||||
exists: fs.existsSync(
|
||||
path.join(__dirname, "../public", location.imageSrc),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Program images
|
||||
if (location.programOptions) {
|
||||
location.programOptions.forEach(program => {
|
||||
location.programOptions.forEach((program) => {
|
||||
if (program.imageSrc) {
|
||||
imagePaths.push({
|
||||
type: 'Program',
|
||||
type: "Program",
|
||||
name: program.title,
|
||||
path: program.imageSrc,
|
||||
exists: fs.existsSync(path.join(__dirname, '../public', program.imageSrc))
|
||||
exists: fs.existsSync(
|
||||
path.join(__dirname, "../public", program.imageSrc),
|
||||
),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
res.render('admin/test-images', {
|
||||
layout: 'layouts/admin',
|
||||
title: 'Test Image Paths',
|
||||
|
||||
res.render("admin/test-images", {
|
||||
layout: "layouts/admin",
|
||||
title: "Test Image Paths",
|
||||
images: imagePaths,
|
||||
user: req.session.user
|
||||
user: req.session.user,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user