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) => {
});
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 { Post, PostType } from "../models";
export const createPosting = async (posting: PostingType) => {
const newPosting = await Posting.create({
......@@ -10,3 +11,13 @@ export const createPosting = async (posting: PostingType) => {
});
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,26 +8,24 @@ export interface PostingType {
username?: string;
}
const postingSchema = new Schema<PostingType>(
{
title: {
type: String,
required: true,
},
text: {
type: String,
required: true,
},
theme: {
type: String,
},
city: {
type: String,
},
username: {
type: String,
},
} // username 때문에 duplicate key error 발생
);
const postingSchema = new Schema<PostingType>({
title: {
type: String,
required: true,
},
text: {
type: String,
required: true,
},
theme: {
type: String,
},
city: {
type: String,
},
username: {
type: String,
},
});
export default model<PostingType>("Posting", postingSchema);
......@@ -17,7 +17,7 @@ const schema = new Schema<IUser>(
email: {
type: String, //mongoose type인 String으로 일반적인 string과는 겉으로는 대문자 차이
rquired: true,
.: true,
unique: true,
validate: [validateEmail, "이메일을 입력해주세요"],
},
name: { type: String },
......@@ -25,14 +25,14 @@ const schema = new Schema<IUser>(
role: { type: Schema.Types.ObjectId, ref: "Role" },
},
{
toJSON: {
versionKey: false,
transform(doc, ret, options) {
delete ret.password;
},
{
toJSON: {
versionKey: false,
transform(doc, ret, options) {
delete ret.password;
},
}
);
},
}
);
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