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
shopping-mall
Commits
011ac7cb
Commit
011ac7cb
authored
Feb 02, 2021
by
Kim, Subin
Browse files
정리
parent
25eac458
Changes
26
Show whitespace changes
Inline
Side-by-side
server/controllers/category.controller.js
View file @
011ac7cb
...
...
@@ -11,13 +11,12 @@ const getCategory = async (req, res) => {
}
const
getSubCategory
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
req.params=?(getsubcategory)
"
,
req
.
params
);
const
{
sub
}
=
req
.
params
try
{
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
res
.
json
(
subcategory
);
console
.
log
(
"
sub=
"
,
subcategory
);
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
}
...
...
@@ -26,17 +25,16 @@ const getToHome = async (res, req) => {
try
{
const
bestProduct
=
await
Product
.
find
({}).
sort
({
purchase
:
1
}).
limit
(
6
)
const
newProduct
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
}).
limit
(
6
)
// console.log("best=", bestProduct)
// console.log("new=", newProduct)
res
.
json
(
bestProduct
,
newProduct
)
}
catch
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
const
getsubId
=
async
(
req
,
res
,
next
,
ele
)
=>
{
try
{
const
sub
=
await
Category
.
find
({
ele
})
const
sub
=
await
Category
.
find
({
ele
})
if
(
!
sub
)
{
res
.
status
(
404
).
send
(
'
카테고리가 존재하지 않습니다.
'
)
}
req
.
category
=
sub
...
...
server/controllers/kakaopay.controller.js
View file @
011ac7cb
...
...
@@ -2,32 +2,24 @@ import fetch from 'node-fetch'
import
config
from
"
../config.js
"
;
const
success
=
(
req
,
res
)
=>
{
console
.
log
(
'
kakaopay success route
'
)
console
.
log
(
'
req body:
'
,
req
.
body
)
return
res
.
json
({
message
:
'
Success
'
})
}
const
fail
=
(
req
,
res
)
=>
{
console
.
log
(
'
kakaopay fail route
'
)
console
.
log
(
'
req body:
'
,
req
.
body
)
return
res
.
json
({
message
:
'
Failed
'
})
}
const
cancel
=
(
req
,
res
)
=>
{
console
.
log
(
'
kakaopay cancel route
'
)
console
.
log
(
'
req body:
'
,
req
.
body
)
return
res
.
json
({
message
:
'
Canceled
'
})
}
const
singleTest
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
asdaf
"
)
console
.
log
(
req
.
body
)
const
item
=
req
.
body
const
data
=
[]
for
(
let
property
in
item
)
{
...
...
@@ -35,7 +27,7 @@ const singleTest = async (req, res) => {
let
encodedValue
=
encodeURIComponent
(
item
[
property
]);
data
.
push
(
encodedKey
+
"
=
"
+
encodedValue
);
}
const
bodyData
=
data
.
join
(
'
&
'
)
// encode data (application/x-www-form-urlencoded)
const
bodyData
=
data
.
join
(
'
&
'
)
const
response
=
await
fetch
(
'
https://kapi.kakao.com/v1/payment/ready
'
,
{
method
:
'
POST
'
,
headers
:
{
...
...
@@ -45,8 +37,7 @@ const singleTest = async (req, res) => {
body
:
bodyData
,
})
const
resp
=
await
response
.
json
()
console
.
log
(
resp
)
res
.
json
({
redirect_url
:
resp
.
next_redirect_pc_url
})
res
.
json
({
redirect_url
:
resp
.
next_redirect_pc_url
})
}
export
default
{
success
,
fail
,
cancel
,
singleTest
}
\ No newline at end of file
server/controllers/order.controller.js
View file @
011ac7cb
...
...
@@ -20,6 +20,7 @@ const Ordered = async (req, res) => {
const
ordered
=
await
req
.
body
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
db
}
`
)
res
.
json
(
ordered
);
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
}
...
...
@@ -79,12 +80,11 @@ const recommendPro = async (req, res) => {
}
}
])
console
.
log
(
'
recommend=
'
,
recommend
)
const
filteredRecommend
=
recommend
.
filter
((
el
)
=>
String
(
el
.
_id
)
!==
String
(
productId
))
console
.
log
(
'
filtering=
'
,
filteredRecommend
)
res
.
json
(
filteredRecommend
)
}
catch
(
error
)
{
console
.
log
(
'
error in order
'
,
error
)
console
.
log
(
error
)
res
.
status
(
404
).
send
(
'
추천 상품이 없습니다.
'
)
}
}
...
...
server/controllers/product.controller.js
View file @
011ac7cb
...
...
@@ -23,6 +23,7 @@ const regist = async (req, res) => {
}).
save
()
res
.
json
(
newProduct
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
제품 정보 등록에 실패하였습니다. 다시 진행해 주십시오.
'
)
}
}
...
...
@@ -33,6 +34,7 @@ const getToHome = async (req, res) => {
const
newProduct
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
}).
limit
(
6
)
res
.
json
({
bestProduct
,
newProduct
})
}
catch
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
...
...
@@ -53,10 +55,10 @@ const getAll = async (req, res) => {
const
productslist
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
})
const
length
=
productslist
.
length
const
productPiece
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
}).
skip
((
req
.
query
.
page
-
1
)
*
per
).
limit
(
per
)
console
.
log
(
"
products=
"
,
productPiece
)
res
.
json
({
productPiece
,
length
})
}
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
...
...
@@ -78,13 +80,13 @@ const getlist = (req, res) => {
res
.
json
({
productsPiece
,
length
})
}
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
const
per
=
9
;
console
.
log
(
"
query=
"
,
req
.
query
)
try
{
if
(
req
.
query
.
product
&&
req
.
query
.
method
)
{
let
method
=
''
...
...
@@ -157,7 +159,6 @@ const categoryId = async (req, res, next, category) => {
const
productsPiece
=
await
Product
.
find
({
main_category
:
category
,
pro_name
:
{
$regex
:
new
RegExp
(
req
.
query
.
product
)
}
}).
sort
({
createdAt
:
-
1
}).
skip
((
req
.
query
.
page
-
1
)
*
per
).
limit
(
per
)
req
.
productsPiece
=
productsPiece
}
else
{
console
.
log
(
"
else
"
)
const
productslist
=
await
Product
.
find
({
main_category
:
category
}).
sort
({
createdAt
:
-
1
})
const
length
=
productslist
.
length
req
.
length
=
length
...
...
@@ -166,6 +167,7 @@ const categoryId = async (req, res, next, category) => {
}
next
()
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
...
...
@@ -209,6 +211,7 @@ const subname = async (req, res) => {
res
.
send
({
productsPiece
,
length
})
}
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
...
...
@@ -236,6 +239,7 @@ const plusPurchase = async (req, res) => {
}
res
.
send
(
"
구매수 늘리기, 재고수 줄이기 성공
"
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
구매숫자를 늘리지 못함
'
)
}
}
...
...
@@ -249,6 +253,7 @@ const deletePro = async (req, res) => {
}
res
.
send
(
'
삭제 성공
'
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
삭제할 상품을 찾지 못하거나 삭제 중 문제가 발생했습니다.
'
)
}
}
...
...
server/controllers/user.controller.js
View file @
011ac7cb
...
...
@@ -50,7 +50,6 @@ const signup = async (req, res) => {
email
}).
save
()
await
new
Cart
({
userId
:
newUser
.
_id
}).
save
()
console
.
log
(
newUser
)
res
.
json
(
newUser
)
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
@@ -84,7 +83,7 @@ const addorder = async (req, res) => {
const
order
=
await
Order
.
find
({
userId
:
userId
}).
populate
({
path
:
'
products.productId
'
,
model
:
'
Product
'
}).
sort
({
createdAt
:
-
1
})
}).
sort
({
createdAt
:
-
1
})
res
.
status
(
200
).
json
(
order
)
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
server/schemas/Cart.js
View file @
011ac7cb
import
mongoose
from
'
mongoose
'
const
{
String
,
Number
,
Array
,
ObjectId
}
=
mongoose
.
Schema
.
Types
const
{
String
,
Number
,
ObjectId
}
=
mongoose
.
Schema
.
Types
const
CartSchema
=
new
mongoose
.
Schema
({
userId
:
{
type
:
ObjectId
,
...
...
@@ -30,4 +30,5 @@ const CartSchema = new mongoose.Schema({
]
}
})
export
default
mongoose
.
models
.
Cart
||
mongoose
.
model
(
'
Cart
'
,
CartSchema
)
\ No newline at end of file
Prev
1
2
Next
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