comment.js
1.72 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
60
61
62
63
64
65
66
67
68
69
70
71
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.post('/reply',auth,(req,res)=>{
Comment.findAll({
<<<<<<< HEAD
where:{postid: req.params.id},
=======
where:{postid: req.body.id},
>>>>>>> a7a00ce3dcec95df5fd17594f215fe752568dfa5
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('/write',auth,(req,res)=>{
console.log(req.params.id);
try{
Comment.create({
userid : req.session.name,
<<<<<<< HEAD
postid : req.body.id,
=======
postid : req.body.postid,
>>>>>>> a7a00ce3dcec95df5fd17594f215fe752568dfa5
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;