diff --git a/controllers/comment.js b/controllers/comment.js index 53944ade..1f534b45 100644 --- a/controllers/comment.js +++ b/controllers/comment.js @@ -39,20 +39,23 @@ async function getComment(req, res) { async function createComment(req, res) { try { + let { comment_id, postId, name, email, comment, user_id, avatar } = req.body; + if (!name) name = 'Anonymous' + if (!email) email = 'test@email.com' + let date = (new Date()).toLocaleDateString - const { comment_id, name, email, comment, markdown, user_id, avatar } = req.body; console.log(req.body) - const com = await Comments.findOne({ comment_id }); + + // const com = await Comments.findOne({ comment_id }); - if (com) { - logger.error("Comment already exist."); - return res.status(400).json({ msg: "This comment already exists." }) - } + // if (com) { + // logger.error("Comment already exist."); + // return res.status(400).json({ msg: "This comment already exists." }) + // } const newComment = new Comments({ - comment_id, name, email, - comment, markdown, user_id, - blog: req.params.id, avatar + name, email, comment, postId, + blog: postId, date }) await newComment.save() @@ -62,7 +65,7 @@ async function createComment(req, res) { res.json({ msg: "Created a new comment" }); } catch (err) { - + console.log(err) logger.error(err) return res.status(500).json({ msg: err.message }) diff --git a/models/caseStudy.js b/models/caseStudy.js new file mode 100755 index 00000000..5908b9bc --- /dev/null +++ b/models/caseStudy.js @@ -0,0 +1,112 @@ +import mongoose from 'mongoose'; + +const caseStudySchema = new mongoose.Schema({ + headerImg: { + type: Object, + required: true, + }, + name: { + type: String, + required: true, + }, + headline: { + type: String, + required: true, + }, + role: { + type: String, + required: true, + }, + context: { + type: String, + required: true, + }, + img: { + type: Object, + required: true, + }, + title: { + type: String, + required: true, + }, + background: { + type: String, + required: true, + }, + objectives: { + type: String, + required: true, + }, + subHeading: { + type: String, + required: true, + }, + prototype: { + type: String, + required: true, + }, + source: { + type: [String], + required: true, + }, + websites: { + type: [String], + required: true, + }, + app: { + type: [String], + required: true, + }, + design: { + type: String, + required: true, + }, + designImg: { + type: String, + required: true, + }, + designColor: { + type: Object, + required: true, + }, + typography: { + type: Object, + required: true, + }, + uiDesignImg: { + type: [String], + required: true, + }, + userFlows: { + type: String, + required: true, + }, + mainFunctions: { + type: [String], + required: true, + }, + goal: { + type: String, + required: true, + }, + version: { + type: String, + required: true, + }, + tags: { + type: [String] + }, + date: { + type: Date, + }, + createdAt: { + type: Date, + default: Date.now + } +}, { + timestamps: true +}) + +const CaseStudy = mongoose.model('CaseStudy', caseStudySchema); + +export default CaseStudy; diff --git a/models/comment.js b/models/comment.js index 69c7003c..7c3025f8 100644 --- a/models/comment.js +++ b/models/comment.js @@ -17,6 +17,17 @@ const commentSchema = new mongoose.Schema({ type:String, required:"this filed is required" }, + postId: { + type: String, + required: true + }, + date: { + type: String, + required: true + }, + comments: { + type: String, + }, blog:{ type:mongoose.Schema.Types.ObjectId, ref: 'Articles' diff --git a/src/API/CommentsAPI.jsx b/src/API/CommentsAPI.jsx new file mode 100755 index 00000000..a1b9841e --- /dev/null +++ b/src/API/CommentsAPI.jsx @@ -0,0 +1,27 @@ +import { useState, useEffect } from 'react'; +import axios from 'axios' + +function CommentsAPI(id) { + const [comments, setComments] = useState([]) + const [result, setResult] = useState(0) + const [callback, setCallback] = useState(false) + + useEffect(() => { + if (id) { + const getComments = async () => { + const res = await axios.get(`/api/articles/${id}/comments`) + setComments(res.data.comments) + setResult(res.data.result) + } + getComments() + } + }, [callback, id]) + + return { + comments: [comments, setComments], + result: [result, setResult], + callback: [callback, setCallback], + } +} + +export default CommentsAPI;