1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 11:39:36 +02:00

Weather settings view. API: select which keys to get from Config

This commit is contained in:
unknown 2021-05-27 12:30:09 +02:00
parent 216c12a33c
commit 316bc49f5c
8 changed files with 180 additions and 15 deletions

View file

@ -1,6 +1,7 @@
const asyncWrapper = require('../middleware/asyncWrapper');
const ErrorResponse = require('../utils/ErrorResponse');
const Config = require('../models/Config');
const { Op } = require('sequelize');
// @desc Insert new key:value pair
// @route POST /api/config
@ -16,9 +17,26 @@ exports.createPair = asyncWrapper(async (req, res, next) => {
// @desc Get all key:value pairs
// @route GET /api/config
// @route GET /api/config?keys=foo,bar,baz
// @access Public
exports.getAllPairs = asyncWrapper(async (req, res, next) => {
const pairs = await Config.findAll();
let pairs;
if (req.query.keys) {
// Check for specific keys to get in a single query
const keys = req.query.keys
.split(',')
.map((key) => { return { key } });
pairs = await Config.findAll({
where: {
[Op.or]: keys
}
});
} else {
// Else get all
pairs = await Config.findAll();
}
res.status(200).json({
success: true,