forked from UKSOURCE/cms.lams
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.
29 lines
656 B
JavaScript
29 lines
656 B
JavaScript
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;
|