From 73e2edfe2b90ffa8353f470633bad0e76c9807b2 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Mon, 28 Mar 2022 11:36:46 -0700 Subject: [PATCH] server: error on post with no files --- server/src/routes/posts.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/routes/posts.ts b/server/src/routes/posts.ts index 8ce914b8..8c8212a6 100644 --- a/server/src/routes/posts.ts +++ b/server/src/routes/posts.ts @@ -56,6 +56,10 @@ posts.post( throw new Error("All files must have a title") } + if (files.length === 0) { + throw new Error("You must submit at least one file") + } + const newPost = new Post({ title: req.body.title, visibility: req.body.visibility, @@ -75,7 +79,7 @@ posts.post( .update(file.content) .digest("hex") .toString(), - html + html: html || '', }) await newFile.$set("user", req.body.userId) @@ -84,13 +88,12 @@ posts.post( return newFile }) ) - await Promise.all( newFiles.map((file) => { newPost.$add("files", file.id) - newPost.save() }) ) + await newPost.save() res.json(newPost) } catch (e) {