Notes/src/routes/api/settings.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-10-21 21:10:33 -04:00
"use strict";
const express = require('express');
const router = express.Router();
2017-10-15 19:47:05 -04:00
const sql = require('../../services/sql');
2017-11-02 20:48:02 -04:00
const options = require('../../services/options');
2017-10-15 19:47:05 -04:00
const auth = require('../../services/auth');
const wrap = require('express-promise-wrap').wrap;
// options allowed to be updated directly in settings dialog
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
router.get('/all', auth.checkApiAuth, wrap(async (req, res, next) => {
2018-01-28 19:30:14 -05:00
const settings = await sql.getMap("SELECT name, value FROM options");
res.send(settings);
}));
router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
2018-01-28 19:30:14 -05:00
const settings = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
+ ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS);
res.send(settings);
}));
router.post('/', auth.checkApiAuth, wrap(async (req, res, next) => {
2017-10-24 22:58:59 -04:00
const body = req.body;
2018-01-28 21:57:46 -05:00
const sourceId = req.headers.source_id;
if (ALLOWED_OPTIONS.includes(body['name'])) {
2017-11-02 20:48:02 -04:00
const optionName = await options.getOption(body['name']);
await sql.doInTransaction(async () => {
await options.setOption(body['name'], body['value'], sourceId);
});
res.send({});
}
else {
res.send("not allowed option to set");
}
}));
module.exports = router;