fea Visa-VisaDetail

This commit is contained in:
r2xrzh9q2z-lab
2026-02-05 12:49:59 +07:00
parent c3a55b13f8
commit ae468e7f26
6 changed files with 1319 additions and 1270 deletions

View File

@@ -47,9 +47,9 @@ const Visa = require("../models/visa");
const slugify = require("slugify"); const slugify = require("slugify");
const createSlug = (text) => { const createSlug = (text) => {
return slugify(text, { return slugify(text, {
lower: true, // Chuyển về chữ thường lower: true,
strict: true, // Loại bỏ ký tự đặc biệt strict: true,
locale: "vi", // Xử lý tiếng Việt chuẩn locale: "en",
trim: true, trim: true,
}); });
}; };
@@ -57,7 +57,7 @@ const createSlug = (text) => {
// Get visa data from MongoDB // Get visa data from MongoDB
const getVisaData = async () => { const getVisaData = async () => {
const visa = await Visa.findOne().sort({ updatedAt: -1 }).lean(); const visa = await Visa.findOne().sort({ updatedAt: -1 });
return visa || {}; return visa || {};
}; };
@@ -324,11 +324,11 @@ exports.updateCountry = async (req, res) => {
const { id } = req.params; const { id } = req.params;
let visaData = await getVisaData(); let visaData = await getVisaData();
// if (!visaData || !visaData.hero || !visaData.hero.summaryList) { if (!visaData || !visaData.hero || !visaData.hero.summaryList) {
// return res return res
// .status(400) .status(400)
// .json({ error: "Cấu trúc dữ liệu Visa không hợp lệ" }); .json({ error: "Cấu trúc dữ liệu Visa không hợp lệ" });
// } }
// 2. Tìm index theo ID (Chuyển về Number để so sánh chính xác) // 2. Tìm index theo ID (Chuyển về Number để so sánh chính xác)
const countryIndex = visaData.hero.summaryList.findIndex( const countryIndex = visaData.hero.summaryList.findIndex(
@@ -413,43 +413,51 @@ exports.updateCountry = async (req, res) => {
// Delete country // Delete country
exports.deleteCountry = async (req, res) => { exports.deleteCountry = async (req, res) => {
try { try {
const { slug } = req.params; // 1. Lấy id từ params
const { id } = req.params;
let visaData = await getVisaData(); let visaData = await getVisaData();
if (!visaData.hero || !visaData.hero.summaryList) { if (!visaData || !visaData.hero || !visaData.hero.summaryList) {
return res.status(400).json({ error: "Invalid visa data structure" }); return res
.status(400)
.json({ success: false, error: "Cấu trúc dữ liệu Visa không hợp lệ" });
} }
// 2. Tìm index theo ID (Chuyển về Number để so sánh chính xác)
const countryIndex = visaData.hero.summaryList.findIndex( const countryIndex = visaData.hero.summaryList.findIndex(
(c) => c.slug === slug, (c) => c.id === parseInt(id),
); );
if (countryIndex === -1) { if (countryIndex === -1) {
return res.status(404).json({ error: `Country "${slug}" not found` }); return res.status(404).json({
success: false,
error: `Không tìm thấy quốc gia có ID: ${id}`,
});
} }
// 3. Xóa phần tử khỏi mảng
const deletedCountry = visaData.hero.summaryList[countryIndex]; const deletedCountry = visaData.hero.summaryList[countryIndex];
visaData.hero.summaryList.splice(countryIndex, 1); visaData.hero.summaryList.splice(countryIndex, 1);
// Update database // 4. Cập nhật vào Database
const updatedData = { if (visaData.markModified) {
...(visaData.toObject ? visaData.toObject() : visaData), visaData.markModified("hero.summaryList");
};
if (visaData._id) {
await Visa.findByIdAndUpdate(visaData._id, updatedData, { new: true });
} else {
await Visa.create(updatedData);
} }
console.log(`✅ Country "${deletedCountry.name}" deleted successfully`); if (visaData._id) {
res.json({ await visaData.save();
} else {
await Visa.create(visaData);
}
console.log(`✅ Deleted Successfully: "${deletedCountry.name}"`);
return res.json({
success: true, success: true,
message: `Country "${deletedCountry.name}" deleted successfully`, message: `Country "${deletedCountry.name}" Deleted Successfully`,
}); });
} catch (err) { } catch (err) {
console.error("Delete country error:", err); console.error("❌ Error Delete:", err);
res.status(500).json({ error: err.message }); return res.status(500).json({ success: false, error: err.message });
} }
}; };
@@ -469,9 +477,7 @@ exports.api = async (req, res) => {
const heroData = visaData?.hero; const heroData = visaData?.hero;
// 2. Lấy riêng phần hero (Dùng biến mới, không gán đè vào const) // 2. Lấy riêng phần hero (Dùng biến mới, không gán đè vào const)
const baseUrl = const processedData = heroData;
process.env.BACKEND_URL || `${req.protocol}://${req.get("host")}`;
const processedData = addBaseUrlToImages(heroData, baseUrl);
return res.json({ return res.json({
success: true, success: true,
@@ -552,20 +558,16 @@ exports.apiCountry = async (req, res) => {
data: null, data: null,
}); });
} }
const baseUrl =
process.env.BACKEND_URL || `${req.protocol}://${req.get("host")}`;
// 3. Chỉ lấy phần chi tiết (detailed view) // 3. Chỉ lấy phần chi tiết (detailed view)
// Lưu ý: Chúng ta copy ra object mới để tránh tham chiếu dữ liệu gốc // Lưu ý: Chúng ta copy ra object mới để tránh tham chiếu dữ liệu gốc
const detailedData = JSON.parse(JSON.stringify(country.viewDetail)); const detailedData = JSON.parse(JSON.stringify(country.viewDetail));
// 4. Gắn baseUrl vào các ảnh nằm trong phần chi tiết này // 4. Gắn baseUrl vào các ảnh nằm trong phần chi tiết này
const processedData = addBaseUrlToImages(detailedData, baseUrl); const processedData = detailedData;
return res.json({ return res.json({
success: true, success: true,
data: processedData, // Trả về nội dung của detailedView data: processedData,
}); });
} catch (err) { } catch (err) {
console.error("Visa country API error:", err); console.error("Visa country API error:", err);

View File

@@ -40,8 +40,8 @@ router.post("/home/update", ensureAuthenticated, homeController.update);
// Middleware chuẩn hóa code // Middleware chuẩn hóa code
router.param("code", (req, res, next, code) => { router.param("code", (req, res, next, code) => {
req.params.code = code.toUpperCase(); req.params.code = code.toUpperCase();
next(); next();
}); });
// About // About
@@ -50,51 +50,125 @@ router.post("/about/update", ensureAuthenticated, aboutController.update);
// AboutUs admin CRUD // AboutUs admin CRUD
router.get("/about-us", ensureAuthenticated, aboutUsController.index); 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.post("/about-us/create", ensureAuthenticated, aboutUsController.create);
router.get("/about-us/:id/edit", ensureAuthenticated, aboutUsController.editForm); router.get(
router.post("/about-us/:id/update", ensureAuthenticated, aboutUsController.update); "/about-us/:id/edit",
router.post("/about-us/:id/delete", ensureAuthenticated, aboutUsController.delete); ensureAuthenticated,
router.get("/about-us/:id/preview", ensureAuthenticated, aboutUsController.preview); 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 // Booking admin CRUD removed
// Form Management // Form Management
router.get("/form", ensureAuthenticated, formController.index); router.get("/form", ensureAuthenticated, formController.index);
router.post("/form/update", ensureAuthenticated, formController.updateDefaultForm); router.post(
"/form/update",
ensureAuthenticated,
formController.updateDefaultForm,
);
// Upload routes // Upload routes
router.get("/upload", ensureAuthenticated, (req, res) => { router.get("/upload", ensureAuthenticated, (req, res) => {
res.render("admin/upload/index", { res.render("admin/upload/index", {
layout: "layouts/admin", layout: "layouts/admin",
title: "Quản lý Upload Ảnh", title: "Quản lý Upload Ảnh",
user: req.session.user, user: req.session.user,
}); });
}); });
router.post("/upload/image", ensureAuthenticated, upload.single("image"), uploadController.uploadImage); router.post(
router.post("/upload/video", ensureAuthenticated, uploadVideo.single("video"), uploadController.uploadVideo); "/upload/image",
router.post("/upload/update-path", ensureAuthenticated, uploadController.updateImagePath); ensureAuthenticated,
router.post("/upload/delete", ensureAuthenticated, uploadController.deleteImage); 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 // Header routes
router.get("/header", ensureAuthenticated, headerController.index); router.get("/header", ensureAuthenticated, headerController.index);
router.post("/header/update", ensureAuthenticated, headerController.update); router.post("/header/update", ensureAuthenticated, headerController.update);
router.get("/header/data", ensureAuthenticated, headerController.api); // Normalized from getHeaderData router.get("/header/data", ensureAuthenticated, headerController.api); // Normalized from getHeaderData
router.patch("/header/:id/status", ensureAuthenticated, headerController.updateStatus); router.patch(
"/header/:id/status",
ensureAuthenticated,
headerController.updateStatus,
);
router.delete("/header/:id", ensureAuthenticated, headerController.destroy); router.delete("/header/:id", ensureAuthenticated, headerController.destroy);
// Header Menu INTEGRATED routes // Header Menu INTEGRATED routes
router.post("/header/menu/create", ensureAuthenticated, headerMenuController.store); router.post(
router.post("/header/menu/update/:id", ensureAuthenticated, headerMenuController.update); "/header/menu/create",
router.post("/header/menu/delete", ensureAuthenticated, headerMenuController.destroy); ensureAuthenticated,
router.post("/header/menu/reorder", ensureAuthenticated, headerMenuController.reorder); 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,
);
// Social Links routes // Social Links routes
router.get("/social-links", ensureAuthenticated, socialLinkController.index); router.get("/social-links", ensureAuthenticated, socialLinkController.index);
router.post("/social-links", ensureAuthenticated, socialLinkController.store); router.post("/social-links", ensureAuthenticated, socialLinkController.store);
router.put("/social-links/:platform", ensureAuthenticated, socialLinkController.update); router.put(
router.delete("/social-links/:platform", ensureAuthenticated, socialLinkController.destroy); "/social-links/:platform",
router.post("/social-links/reorder", ensureAuthenticated, socialLinkController.reorder); ensureAuthenticated,
socialLinkController.update,
);
router.delete(
"/social-links/:platform",
ensureAuthenticated,
socialLinkController.destroy,
);
router.post(
"/social-links/reorder",
ensureAuthenticated,
socialLinkController.reorder,
);
// Footer routes // Footer routes
router.get("/footer", ensureAuthenticated, footerController.index); router.get("/footer", ensureAuthenticated, footerController.index);
@@ -104,60 +178,160 @@ router.get("/footer/data", ensureAuthenticated, footerController.getFooterData);
// Contact routes // Contact routes
router.get("/contact", ensureAuthenticated, contactController.index); router.get("/contact", ensureAuthenticated, contactController.index);
router.post("/contact/update", ensureAuthenticated, contactController.update); router.post("/contact/update", ensureAuthenticated, contactController.update);
router.get("/contact/data", ensureAuthenticated, contactController.getContactData); router.get(
"/contact/data",
ensureAuthenticated,
contactController.getContactData,
);
// Contact submissions management // Contact submissions management
router.get("/contact/submissions", ensureAuthenticated, contactController.getSubmissions); router.get(
router.put("/contact/submissions/:id", ensureAuthenticated, contactController.updateSubmissionStatus); "/contact/submissions",
ensureAuthenticated,
contactController.getSubmissions,
);
router.put(
"/contact/submissions/:id",
ensureAuthenticated,
contactController.updateSubmissionStatus,
);
// Appointment management // Appointment management
const appointmentController = require("../controllers/appointmentController"); const appointmentController = require("../controllers/appointmentController");
router.get("/appointments", ensureAuthenticated, appointmentController.getAppointments); router.get(
router.get("/appointments/:id", ensureAuthenticated, appointmentController.getAppointmentById); "/appointments",
router.put("/appointments/:id", ensureAuthenticated, appointmentController.updateAppointmentStatus); ensureAuthenticated,
router.delete("/appointments/:id", ensureAuthenticated, appointmentController.deleteAppointment); 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 // Appointment CMS page management
router.get("/appointment", ensureAuthenticated, appointmentController.index); router.get("/appointment", ensureAuthenticated, appointmentController.index);
router.post("/appointment/update", ensureAuthenticated, appointmentController.update); router.post(
router.get("/appointment/data", ensureAuthenticated, appointmentController.getAppointmentData); "/appointment/update",
ensureAuthenticated,
appointmentController.update,
);
router.get(
"/appointment/data",
ensureAuthenticated,
appointmentController.getAppointmentData,
);
// Pricing CMS page management // Pricing CMS page management
const pricingController = require("../controllers/pricingController"); const pricingController = require("../controllers/pricingController");
router.get("/pricing", ensureAuthenticated, pricingController.index); router.get("/pricing", ensureAuthenticated, pricingController.index);
router.post("/pricing/update", ensureAuthenticated, pricingController.update); router.post("/pricing/update", ensureAuthenticated, pricingController.update);
router.get("/pricing/data", ensureAuthenticated, pricingController.getPricingData); router.get(
"/pricing/data",
ensureAuthenticated,
pricingController.getPricingData,
);
// Activity CRUD routes // Activity CRUD routes
router.get("/activity", ensureAuthenticated, activityController.index); 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); router.post("/activity/create", ensureAuthenticated, activityController.create);
// Update filters (place before any parameterized /activity/:id routes to avoid route collision) // 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) // Update hero (global hero section for activities)
router.post("/activity/hero/update", ensureAuthenticated, activityController.updateHero); router.post(
router.get("/activity/:id/edit", ensureAuthenticated, activityController.editForm); "/activity/hero/update",
router.post("/activity/:id/update", ensureAuthenticated, activityController.update); ensureAuthenticated,
router.post("/activity/:id/delete", ensureAuthenticated, activityController.delete); activityController.updateHero,
router.post("/activity/:id/toggle-status", ensureAuthenticated, activityController.toggleStatus); );
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 // Update display order
router.post("/activity/update-order", ensureAuthenticated, activityController.updateOrder); router.post(
"/activity/update-order",
ensureAuthenticated,
activityController.updateOrder,
);
// Booking submissions routes // Booking submissions routes
router.get("/activity/:id/bookings/count", ensureAuthenticated, activityController.getBookingCount); router.get(
router.get("/activity/:id/bookings", ensureAuthenticated, activityController.getBookingSubmissions); "/activity/:id/bookings/count",
router.get("/activity/:id/bookings/export", ensureAuthenticated, activityController.exportBookingData); 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) // 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 // Update booking submission
router.put("/bookings/:bookingId", ensureAuthenticated, bookingSubmissionController.updateBookingSubmission); router.put(
"/bookings/:bookingId",
ensureAuthenticated,
bookingSubmissionController.updateBookingSubmission,
);
// Delete booking submission // Delete booking submission
router.delete("/bookings/:bookingId", ensureAuthenticated, bookingSubmissionController.deleteBookingSubmission); router.delete(
"/bookings/:bookingId",
ensureAuthenticated,
bookingSubmissionController.deleteBookingSubmission,
);
// Update filters // Update filters
// Preview activity // 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 // FAQ routes - Thêm vào đây
router.get("/faq", ensureAuthenticated, faqController.index); router.get("/faq", ensureAuthenticated, faqController.index);
@@ -257,6 +431,69 @@ router.post(
serviceController.updateDetails, 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");
// 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,
});
});
// Display visa management page // Display visa management page
router.get("/visa", ensureAuthenticated, visaController.index); router.get("/visa", ensureAuthenticated, visaController.index);
@@ -264,7 +501,7 @@ router.get("/visa", ensureAuthenticated, visaController.index);
router.get("/visa/edit/:id", ensureAuthenticated, visaController.getCountry); router.get("/visa/edit/:id", ensureAuthenticated, visaController.getCountry);
// Update hero title // Update hero title
router.post("/visa/update", ensureAuthenticated, visaController.update); router.post("/visa/update", ensureAuthenticated, visaController.updateCountry);
// Add new country // Add new country
router.post("/visa/add", ensureAuthenticated, visaController.addCountry); router.post("/visa/add", ensureAuthenticated, visaController.addCountry);
@@ -278,7 +515,7 @@ router.put(
// Delete country // Delete country
router.delete( router.delete(
"/delete/:slug", "/visa/delete/:id",
ensureAuthenticated, ensureAuthenticated,
visaController.deleteCountry, visaController.deleteCountry,
); );
@@ -292,9 +529,21 @@ router.post("/blog/:id/edit", ensureAuthenticated, blogController.update);
router.post("/blog/:id/delete", ensureAuthenticated, blogController.destroy); router.post("/blog/:id/delete", ensureAuthenticated, blogController.destroy);
// Comment management routes // Comment management routes
router.post("/blog/:blogId/comments/:commentId/approve", ensureAuthenticated, blogController.approveComment); router.post(
router.post("/blog/:blogId/comments/:commentId/reject", ensureAuthenticated, blogController.rejectComment); "/blog/:blogId/comments/:commentId/approve",
router.post("/blog/:blogId/comments/:commentId/delete", ensureAuthenticated, blogController.deleteComment); 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 // Blog Categories Management
router.get( router.get(

View File

@@ -273,6 +273,25 @@
</a> </a>
</div> </div>
</div> </div>
<!-- Visa -->
<div class="col-md-4 border-end border-top">
<div class="p-4">
<div class="d-flex align-items-center mb-3">
<div class="rounded-circle d-flex align-items-center justify-content-center me-3"
style="width: 50px; height: 50px; background-color: rgba(184, 183, 106, 0.1);">
<i class="fas fa-passport fa-lg" style="color: var(--primary-color);"></i>
</div>
<div>
<h5 class="mb-0">Visa</h5>
<p class="text-muted mb-0 small">Manage visa countries</p>
</div>
</div>
<a href="/admin/visa" class="btn btn-sm btn-primary w-100 mt-2">
<i class="fas fa-edit me-2"></i>Edit
</a>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

File diff suppressed because it is too large Load Diff

View File

@@ -84,6 +84,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/admin/blog">Blog</a> <a class="nav-link" href="/admin/blog">Blog</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="/admin/visa">Visa</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/admin/blog-category">Blog Category</a> <a class="nav-link" href="/admin/blog-category">Blog Category</a>
</li> </li>

View File

@@ -772,6 +772,10 @@
<a class="nav-link <%= currentPath === '/admin/blog' ? 'active' : '' %>" <a class="nav-link <%= currentPath === '/admin/blog' ? 'active' : '' %>"
href="/admin/blog">Blog</a> href="/admin/blog">Blog</a>
</li> </li>
<li class="nav-item">
<a class="nav-link <%= currentPath === '/admin/visa' ? 'active' : '' %>"
href="/admin/visa">Visa</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link <%= currentPath === '/admin/contact' ? 'active' : '' %>" <a class="nav-link <%= currentPath === '/admin/contact' ? 'active' : '' %>"
href="/admin/contact">Contact Us</a> href="/admin/contact">Contact Us</a>