post.js
1.49 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연결
//현재 로그인된 사용자의 게시물 배열 응답
router.get('/',auth,(req,res)=>{
Post.findAll({
where:{mbti: req.session.personality},
order: [['created_at', 'DESC']],
})
.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('/',auth,(req,res)=>{
try{
Post.create({
userid : req.session.name,
title : req.body.title,
post: req.body.content,
status: false,
mbti : req.session.personality
})
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;