aboutsummaryrefslogtreecommitdiffstats
path: root/backend/routes/forms/new.py
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-12-12 14:32:13 +0000
committerGravatar GitHub <[email protected]>2020-12-12 14:32:13 +0000
commit35626c80026931dc7306f06bcd5e7cdc70d4dddc (patch)
treea7649a765812096a21a87b8089f5977517c80a43 /backend/routes/forms/new.py
parentMerge pull request #16 from python-discord/add-form-response-schema (diff)
parentMake JSON errors more JS friendly and add response codes (diff)
Merge pull request #17 from python-discord/ks123/response-model-endpoint
Diffstat (limited to 'backend/routes/forms/new.py')
-rw-r--r--backend/routes/forms/new.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/backend/routes/forms/new.py b/backend/routes/forms/new.py
index ff39f12..6437a4a 100644
--- a/backend/routes/forms/new.py
+++ b/backend/routes/forms/new.py
@@ -26,5 +26,10 @@ class FormCreate(Route):
except ValidationError as e:
return JSONResponse(e.errors())
+ if await request.state.db.forms.find_one({"_id": form.id}):
+ return JSONResponse({
+ "error": "Form with same ID already exists."
+ }, status_code=400)
+
await request.state.db.forms.insert_one(form.dict(by_alias=True))
return JSONResponse(form.dict())