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
b8dcc783
Commit
b8dcc783
authored
Jul 11, 2022
by
Lee Soobeom
Browse files
duplicate key error
parent
0ce1f449
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/controllers/post.controller.ts
View file @
b8dcc783
...
...
@@ -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로 보내기
});
src/db/post.db.ts
View file @
b8dcc783
...
...
@@ -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
,
});
};
src/models/posting.model.ts
View file @
b8dcc783
...
...
@@ -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
);
src/routes/post.route.ts
View file @
b8dcc783
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
;
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