Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
94bd52bc
Commit
94bd52bc
authored
Jul 11, 2022
by
Lee Soobeom
Browse files
mongoose Types error
parent
ca4f7ed1
Changes
5
Show whitespace changes
Inline
Side-by-side
package.json
View file @
94bd52bc
...
...
@@ -38,7 +38,7 @@
"
cookie-parser
"
:
"
^1.4.6
"
,
"
express
"
:
"
^4.18.1
"
,
"
jsonwebtoken
"
:
"
^8.5.1
"
,
"
mongoose
"
:
"
^6.4.
2
"
,
"
mongoose
"
:
"
^6.4.
4
"
,
"
validator
"
:
"
^13.7.0
"
}
}
src/controllers/post.controller.ts
View file @
94bd52bc
...
...
@@ -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로 보내기
});
src/db/post.db.ts
View file @
94bd52bc
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
,
});
};
src/models/posting.model.ts
View file @
94bd52bc
...
...
@@ -8,8 +8,7 @@ export interface PostingType {
username
?:
string
;
}
const
postingSchema
=
new
Schema
<
PostingType
>
(
{
const
postingSchema
=
new
Schema
<
PostingType
>
({
title
:
{
type
:
String
,
required
:
true
,
...
...
@@ -27,7 +26,6 @@ const postingSchema = new Schema<PostingType>(
username
:
{
type
:
String
,
},
}
// username 때문에 duplicate key error 발생
);
});
export
default
model
<
PostingType
>
(
"
Posting
"
,
postingSchema
);
src/models/user.model.ts
View file @
94bd52bc
...
...
@@ -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
},
...
...
@@ -33,6 +33,6 @@ const schema = new Schema<IUser>(
},
},
}
);
);
export
default
model
<
IUser
>
(
"
User
"
,
schema
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment