From f6e0bae6283b44ec6b80a29ba4ca45efd0cf7549 Mon Sep 17 00:00:00 2001
From: hoseacodes <dominique11h@yahoo.com>
Date: Mon, 19 Feb 2024 00:11:49 -0600
Subject: [PATCH] fix(*): update backend articles

---
 controllers/article.js | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/controllers/article.js b/controllers/article.js
index e245f421..6049186e 100755
--- a/controllers/article.js
+++ b/controllers/article.js
@@ -65,24 +65,20 @@ async function createArticle(req, res) {
         const { article_id, title, subtitle, markdown, description, images, category, dev, medium, postedBy } = req.body;
 
         if (!images) {
-
           logger.error("No image provided.");
           return res.status(400).json({ msg: "No image upload" });
         }
 
         const article = await Articles.find({ article_id });
-
-        // if (article) {
-
-        //   logger.error("Article already exist.");
-
-        //   return res.status(400).json({ msg: "This article already exists." })
-        // }
+        if (article.length > 0) {
+          logger.error("Article already exist.");
+          return res.status(400).json({ msg: "This article already exists." })
+        }
 
         const newArticle = new Articles({
-          article_id, title, subtitle, markdown, description, images, category, postedBy
+          article_id, title, subtitle, markdown, description, images, postedBy
         })
-
+      
         try {
           if (dev) {
             await axios.post('https://dev.to/api/articles',
@@ -131,9 +127,8 @@ async function createArticle(req, res) {
 
         res.json({ msg: "Created a new article" });
     } catch (err) {
-
+          console.log(err, "error");
         logger.error(err)
-
         return res.status(500).json({ msg: err.message })
     }
 }