forked from UKSOURCE/cms.lams
feat(cms): add management for partnerships, history, accreditation, admissions, and policies pages
Implement a singleton page content system to manage static informational pages. This includes: - New controllers, models, and data files for Partnerships, History, Accreditation, Admissions, and Policies. - Admin routes and views for updating page content. - Public API endpoints for fetching page data. - Migration scripts for initializing page data. - Updated admin navigation layout to include a dropdown for "About" sections. - Audit action constants for tracking updates to these pages.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
require("dotenv").config();
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const connectDB = require("../config/database");
|
||||
|
||||
async function migrateSingletonPage({
|
||||
migrationName,
|
||||
modelPath,
|
||||
dataFile,
|
||||
label,
|
||||
}) {
|
||||
try {
|
||||
await connectDB();
|
||||
console.log(`🚀 Starting migration: ${migrationName}...`);
|
||||
|
||||
const Model = require(modelPath);
|
||||
console.log(`✅ ${label} model registered successfully`);
|
||||
|
||||
const dataPath = path.join(__dirname, "..", "data", dataFile);
|
||||
const raw = await fs.readFile(dataPath, "utf8");
|
||||
const pageData = JSON.parse(raw);
|
||||
console.log(`📖 ${label} data loaded from: ${dataPath}`);
|
||||
|
||||
await Model.deleteMany({});
|
||||
console.log(`🧹 Existing ${label} documents cleared`);
|
||||
|
||||
const created = await Model.create(pageData);
|
||||
console.log(`✅ ${label} document created with _id: ${created._id.toString()}`);
|
||||
|
||||
console.log(`🎉 Migration ${migrationName} completed successfully.`);
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error(`❌ Migration ${migrationName} failed:`, error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = migrateSingletonPage;
|
||||
Reference in New Issue
Block a user