diff options
author | vantezzen <properly@protonmail.com> | 2019-08-26 21:26:59 +0200 |
---|---|---|
committer | vantezzen <properly@protonmail.com> | 2019-08-26 21:26:59 +0200 |
commit | 26b9ae22724862fac562052d254e0a2f42fadca5 (patch) | |
tree | dc65c4b7a1ee22896de0a6c84abe277de7708790 /app/Controllers | |
parent | Add validations (diff) | |
download | ferdium-server-26b9ae22724862fac562052d254e0a2f42fadca5.tar.gz ferdium-server-26b9ae22724862fac562052d254e0a2f42fadca5.tar.zst ferdium-server-26b9ae22724862fac562052d254e0a2f42fadca5.zip |
Improve recipe creation
Diffstat (limited to 'app/Controllers')
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js index 11938b6..ec0cde9 100644 --- a/app/Controllers/Http/RecipeController.js +++ b/app/Controllers/Http/RecipeController.js | |||
@@ -6,6 +6,7 @@ const Drive = use('Drive') | |||
6 | const { | 6 | const { |
7 | validateAll | 7 | validateAll |
8 | } = use('Validator'); | 8 | } = use('Validator'); |
9 | const Env = use('Env') | ||
9 | 10 | ||
10 | const fetch = require('node-fetch'); | 11 | const fetch = require('node-fetch'); |
11 | const targz = require('targz'); | 12 | const targz = require('targz'); |
@@ -53,18 +54,23 @@ class RecipeController { | |||
53 | request, | 54 | request, |
54 | response | 55 | response |
55 | }) { | 56 | }) { |
57 | // Check if recipe creation is enabled | ||
58 | if (Env.get('IS_CREATION_ENABLED') == 'false') { | ||
59 | return response.send('This server doesn\'t allow the creation of new recipes.'); | ||
60 | } | ||
61 | |||
56 | // Validate user input | 62 | // Validate user input |
57 | const validation = await validateAll(request.all(), { | 63 | const validation = await validateAll(request.all(), { |
58 | name: 'required|alpha', | 64 | name: 'required|alpha', |
59 | recipeId: 'required|unique:recipes,recipeId', | 65 | id: 'required|unique:recipes,recipeId', |
60 | author: 'required|accepted', | 66 | author: 'required|accepted', |
61 | png: 'required|url', | 67 | png: 'required|url', |
62 | svg: 'required|url', | 68 | svg: 'required|url', |
63 | files: 'required', | ||
64 | }); | 69 | }); |
65 | if (validation.fails()) { | 70 | if (validation.fails()) { |
66 | return response.status(401).send({ | 71 | return response.status(401).send({ |
67 | "message": "Invalid POST arguments", | 72 | "message": "Invalid POST arguments", |
73 | "messages": validation.messages(), | ||
68 | "status": 401 | 74 | "status": 401 |
69 | }) | 75 | }) |
70 | } | 76 | } |
@@ -126,6 +132,7 @@ class RecipeController { | |||
126 | if (validation.fails()) { | 132 | if (validation.fails()) { |
127 | return response.status(401).send({ | 133 | return response.status(401).send({ |
128 | "message": "Please provide a needle", | 134 | "message": "Please provide a needle", |
135 | "messages": validation.messages(), | ||
129 | "status": 401 | 136 | "status": 401 |
130 | }) | 137 | }) |
131 | } | 138 | } |
@@ -162,6 +169,7 @@ class RecipeController { | |||
162 | if (validation.fails()) { | 169 | if (validation.fails()) { |
163 | return response.status(401).send({ | 170 | return response.status(401).send({ |
164 | "message": "Please provide a recipe ID", | 171 | "message": "Please provide a recipe ID", |
172 | "messages": validation.messages(), | ||
165 | "status": 401 | 173 | "status": 401 |
166 | }) | 174 | }) |
167 | } | 175 | } |