The DTP Sites web app development engine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.3 KiB

// admin/settings.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
const DTP_COMPONENT_NAME = 'admin:settings';
const express = require('express');
const { SiteController } = require('../../../lib/site-lib');
class SettingsController extends SiteController {
constructor (dtp) {
super(dtp, DTP_COMPONENT_NAME);
}
async start ( ) {
const router = express.Router();
router.use(async (req, res, next) => {
res.locals.currentView = 'admin';
res.locals.adminView = 'settings';
return next();
});
router.post('/', this.postUpdateSettings.bind(this));
router.get('/', this.getSettingsView.bind(this));
return router;
}
async postUpdateSettings (req, res, next) {
const { cache: cacheService } = this.dtp.services;
try {
const settingsKey = `settings:${this.dtp.config.site.domainKey}:site`;
await cacheService.setObject(settingsKey, req.body);
res.redirect('/admin/settings');
} catch (error) {
return next(error);
}
}
async getSettingsView (req, res, next) {
try {
res.render('admin/settings/editor');
} catch (error) {
return next(error);
}
}
}
module.exports = async (dtp) => {
let controller = new SettingsController(dtp);
return controller;
};