Skip to content

Commit

Permalink
fix(*): update backend articles
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed Feb 19, 2024
1 parent 9db71a5 commit f6e0bae
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 })
}
}
Expand Down

0 comments on commit f6e0bae

Please sign in to comment.