-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15ce8bb
commit f07b7f3
Showing
4 changed files
with
163 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = '[email protected]' | ||
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 }) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |