Commit 94bd52bc authored by Lee Soobeom's avatar Lee Soobeom
Browse files

mongoose Types error

parent ca4f7ed1
...@@ -41,3 +41,15 @@ export const posting = asyncWrap(async (req, res) => { ...@@ -41,3 +41,15 @@ export const posting = asyncWrap(async (req, res) => {
}); });
return res.json(newPosting); 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로 보내기
});
import { Posting, PostingType } from "../models"; import { Posting, PostingType } from "../models";
import { Post, PostType } from "../models";
export const createPosting = async (posting: PostingType) => { export const createPosting = async (posting: PostingType) => {
const newPosting = await Posting.create({ const newPosting = await Posting.create({
...@@ -10,3 +11,13 @@ export const createPosting = async (posting: PostingType) => { ...@@ -10,3 +11,13 @@ export const createPosting = async (posting: PostingType) => {
}); });
return newPosting; 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,
});
};
...@@ -8,8 +8,7 @@ export interface PostingType { ...@@ -8,8 +8,7 @@ export interface PostingType {
username?: string; username?: string;
} }
const postingSchema = new Schema<PostingType>( const postingSchema = new Schema<PostingType>({
{
title: { title: {
type: String, type: String,
required: true, required: true,
...@@ -27,7 +26,6 @@ const postingSchema = new Schema<PostingType>( ...@@ -27,7 +26,6 @@ const postingSchema = new Schema<PostingType>(
username: { username: {
type: String, type: String,
}, },
} // username 때문에 duplicate key error 발생 });
);
export default model<PostingType>("Posting", postingSchema); export default model<PostingType>("Posting", postingSchema);
...@@ -17,7 +17,7 @@ const schema = new Schema<IUser>( ...@@ -17,7 +17,7 @@ const schema = new Schema<IUser>(
email: { email: {
type: String, //mongoose type인 String으로 일반적인 string과는 겉으로는 대문자 차이 type: String, //mongoose type인 String으로 일반적인 string과는 겉으로는 대문자 차이
rquired: true, rquired: true,
.: true, unique: true,
validate: [validateEmail, "이메일을 입력해주세요"], validate: [validateEmail, "이메일을 입력해주세요"],
}, },
name: { type: String }, name: { type: String },
...@@ -33,6 +33,6 @@ const schema = new Schema<IUser>( ...@@ -33,6 +33,6 @@ const schema = new Schema<IUser>(
}, },
}, },
} }
); );
export default model<IUser>("User", schema); export default model<IUser>("User", schema);
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