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,28 @@
|
||||
const mongoose = require("mongoose");
|
||||
const jsonHelper = require("../utils/jsonHelper");
|
||||
|
||||
function createSingletonPageModel(modelName, collectionName, dataFileName) {
|
||||
const schema = new mongoose.Schema(
|
||||
{},
|
||||
{
|
||||
strict: false,
|
||||
timestamps: true,
|
||||
collection: collectionName,
|
||||
},
|
||||
);
|
||||
|
||||
schema.statics.getSingle = async function getSingle() {
|
||||
let doc = await this.findOne();
|
||||
|
||||
if (!doc) {
|
||||
const defaultData = jsonHelper.readJsonFile(dataFileName) || {};
|
||||
doc = await this.create(defaultData);
|
||||
}
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
return mongoose.model(modelName, schema);
|
||||
}
|
||||
|
||||
module.exports = createSingletonPageModel;
|
||||
Reference in New Issue
Block a user