mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
API routes to get and add themes
This commit is contained in:
parent
48e28b9abd
commit
b8af178cbf
6 changed files with 67 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const ErrorResponse = require('../../utils/ErrorResponse');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Add custom search query
|
||||
|
@ -8,6 +9,12 @@ const addQuery = asyncWrapper(async (req, res, next) => {
|
|||
const file = new File('data/customQueries.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
const prefixes = content.queries.map((q) => q.prefix);
|
||||
|
||||
if (prefixes.includes(req.body.prefix)) {
|
||||
return next(new ErrorResponse('Prefix must be unique', 400));
|
||||
}
|
||||
|
||||
// Add new query
|
||||
content.queries.push(req.body);
|
||||
file.write(content, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue