diff options
| author | Bobby <[email protected]> | 2022-03-16 22:00:52 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-03-16 22:00:52 -0400 |
| commit | 4ff5c19c9f3c4c9488d8cf70c64e045d5d01d6b8 (patch) | |
| tree | 43db48c3ece7f6b6d6a5303a3424e0613055d309 /routes/posts.js | |
| parent | 339e86edb5c8ad729cf0f4cfac3c3cde081d374e (diff) | |
| download | luciferreeves.github.io-4ff5c19c9f3c4c9488d8cf70c64e045d5d01d6b8.tar.xz luciferreeves.github.io-4ff5c19c9f3c4c9488d8cf70c64e045d5d01d6b8.zip | |
function to get posts
Diffstat (limited to 'routes/posts.js')
| -rw-r--r-- | routes/posts.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/routes/posts.js b/routes/posts.js index d81327f..3ae3a3c 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -8,7 +8,6 @@ router.get("/posts", (req, res) => { let query = store.collection("posts"); query - .limit(1) .get() .then((querySnapshot) => { querySnapshot.forEach((documentSnapshot) => { @@ -23,18 +22,24 @@ router.get("/posts", (req, res) => { router.post("/new", (req, res) => { const { title, content, tags, publishDate } = req.body; const store = firebase.firestore(); + const id = store.collection("posts").doc().id; const post = { + id, title, content, tags: String(tags).split(",").length > 0 ? String(tags).split(",") : [], publishDate, }; let query = store.collection("posts"); - query.add(post).then(() => { - res.json({ success: true }); - }).catch((err) => { - res.json({ success: false, err }); - }); + query + .doc(id) + .set(post) + .then(() => { + res.json({ success: true }); + }) + .catch((err) => { + res.json({ success: false, err }); + }); }); module.exports = router; |
