Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(writeapi): admin settings update route
- Loading branch information
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const meta = require('../../meta'); | ||
|
||
const helpers = require('../helpers'); | ||
|
||
const Admin = module.exports; | ||
|
||
Admin.updateSetting = async (req, res) => { | ||
if (!res.locals.privileges['admin:settings']) { | ||
return helpers.formatApiResponse(403, res); | ||
} | ||
|
||
await meta.configs.set(req.params.setting, req.body.value); | ||
helpers.formatApiResponse(200, res); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const router = require('express').Router(); | ||
const middleware = require('../../middleware'); | ||
const controllers = require('../../controllers'); | ||
const routeHelpers = require('../helpers'); | ||
|
||
const setupApiRoute = routeHelpers.setupApiRoute; | ||
|
||
module.exports = function () { | ||
const middlewares = [middleware.authenticate]; | ||
|
||
setupApiRoute(router, '/settings/:setting', middleware, [...middlewares, middleware.checkRequired.bind(null, ['value']), middleware.exposePrivilegeSet], 'put', controllers.write.admin.updateSetting); | ||
|
||
return router; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters