flame/controllers/queries/addQuery.js

22 lines
534 B
JavaScript
Raw Normal View History

const asyncWrapper = require('../../middleware/asyncWrapper');
const File = require('../../utils/File');
// @desc Add custom search query
// @route POST /api/queries
// @access Public
const addQuery = asyncWrapper(async (req, res, next) => {
const file = new File('data/customQueries.json');
let content = JSON.parse(file.read());
// Add new query
content.queries.push(req.body);
file.write(content, true);
res.status(201).json({
success: true,
data: req.body,
});
});
module.exports = addQuery;