Commit b8dcc783 authored by Lee Soobeom's avatar Lee Soobeom
Browse files

duplicate key error

parent 0ce1f449
......@@ -5,7 +5,7 @@ import { asyncWrap } from "../helpers";
import { postDb } from "../db";
export const posting = asyncWrap(async (req, res) => {
const { title, text, theme, city, username } = req.body;
const { title, text, theme, city, username, date, counts } = req.body;
console.log("body", req.body);
......@@ -38,18 +38,8 @@ export const posting = asyncWrap(async (req, res) => {
theme,
city,
username,
date,
counts,
});
return res.json(newPosting);
});
export const post = asyncWrap(async (req, res) => {
const { title, theme, city, username, date, counts } = req.body;
console.log("body", req.body);
// 1) DB postings에서 title, theme, city, username, date 불러오기
// 2) 불러온 데이터 + counts posts에 저장
// 3) DB posts에서 데이터 불러서 frontend로 보내기
});
......@@ -8,16 +8,8 @@ export const createPosting = async (posting: PostingType) => {
theme: posting.theme,
city: posting.city,
username: posting.username,
date: posting.date,
counts: posting.counts,
});
return newPosting;
};
export const createPost = async (post: PostType) => {
const newPost = await Post.create({
title: post.title,
theme: post.theme,
city: post.city,
date: post.date,
counts: post.counts,
});
};
......@@ -6,6 +6,8 @@ export interface PostingType {
theme: string;
city: string;
username?: string;
date?: string;
counts?: number;
}
const postingSchema = new Schema<PostingType>({
......@@ -26,6 +28,11 @@ const postingSchema = new Schema<PostingType>({
username: {
type: String,
},
date: {
type: Date,
dafault: Date.now,
},
counts: 0,
});
export default model<PostingType>("Posting", postingSchema);
import express from "express";
import { postCtrl } from "../controllers";
import { postCtrl, authCtrl } from "../controllers";
const router = express.Router();
router.route("/").post(postCtrl.posting);
router.route("/").post(authCtrl.requireLogin, postCtrl.posting);
export default router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment