forked from UKSOURCE/cms.lams
feat: add programme module and blog integration
- Add Programme Mongoose model with sub-schemas and migrateFromJson static method - Add programme CRUD controller with audit logging and icon sanitization - Add programme admin views (index, edit) with tabbed form and dynamic arrays - Add seed migration script for programmes - Add /api/programmes and /api/programmes/:id public API endpoints - Register programme routes in admin and public router - Update dashboard with Programmes card and API endpoint entries - Update admin sidebar layout to include Programmes nav link
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
require("dotenv").config();
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const mongoose = require("mongoose");
|
||||
const connectDB = require("../config/database");
|
||||
const Programme = require("../models/programme");
|
||||
|
||||
/**
|
||||
* Seed / upsert all programmes from data/programmes.json into MongoDB.
|
||||
* Run: node scripts/2026_04_20_150000_seed_programmes.js
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
console.log("Connected to MongoDB");
|
||||
|
||||
const jsonPath = path.join(__dirname, "../data/programmes.json");
|
||||
const raw = await fs.readFile(jsonPath, "utf8");
|
||||
const data = JSON.parse(raw);
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error("data/programmes.json must be a JSON array");
|
||||
}
|
||||
|
||||
const results = await Programme.migrateFromJson(data);
|
||||
console.log("Programme migration completed:");
|
||||
results.forEach((r) => console.log(` [${r.action}] id=${r.id}`));
|
||||
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Programme migration error:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
Reference in New Issue
Block a user