refactor: add auto-generated menu for new services

This commit is contained in:
Đỗ Minh Nhật
2026-04-11 05:45:07 +07:00
parent e7929568dc
commit 0109b08b58
4 changed files with 106 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
const { getServiceData } = require("../services/service.service");
const Service = require("../models/service");
const syncServiceMenu = require("../services/syncServiceMenu");
const { addBaseUrlToImages, getFullImageUrl } = require("../utils/imageHelper");
const writeAuditLog = require("../audit/writeAuditLog");
const diffObject = require("../audit/diffObject");
@@ -98,6 +99,8 @@ exports.updateService = async (req, res) => {
changes,
req,
});
// Sync header menu children to reflect updated service name/slug
await syncServiceMenu(updatedData.services?.items || []);
req.flash("success_msg", "Service updated successfully");
res.redirect("/admin/service");
} catch (err) {
@@ -168,6 +171,9 @@ exports.update = async (req, res) => {
await Service.create(updatedData);
}
// Sync header menu children to reflect current service list
await syncServiceMenu(updatedData.services?.items || []);
req.flash("success_msg", "Service updated successfully");
res.redirect("/admin/service");
} catch (err) {