comment.js
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require("express");
const bodyParser = require("body-parser");
const router = express.Router();
const auth = require("../obj/authorize");
const {User}=require('../models'); //유저정보 db연결
const {Post}=require('../models'); //게시물정보 db연결
const {Comment}=require('../models');
//현재 로그인된 사용자의 게시물 배열 응답
router.get('/:boardId',auth,(req,res)=>{
Comment.findAll({
where:{postid: req.params.boardId},
order: [['created_at', 'ASC']],
})
.then((result)=>{
//console.log(result);
res.send(result);
//게시물이 0개인 경우
// if(result === null || result === undefined){
// console.log("해당유저의 게시물이 없습니다.")
// res.status(401).send("null");
// }
// else{
// console.log(result.length);
// res.sendStatus(200);
// }
})
});
//게시물 작성
router.post('/:boardId',auth,(req,res)=>{
try{
Comment.create({
userid : req.session.name,
postid : req.params.boardId,
comment : req.body.comment,
})
console.log("게시");
res.sendStatus(200);
} catch(err){
console.log("실패");
res.send(err);
}
/*
User.create({
name: req.body.Id,
pw:req.body.Password,
personality:req.body.Personality,
status:false
*/
});
module.exports = router;