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
9e604666
Commit
9e604666
authored
Jan 25, 2021
by
이재연
Browse files
Merge remote-tracking branch 'origin/jiwon' into jaeyeon
parents
d8de2d3f
506fb316
Changes
34
Hide whitespace changes
Inline
Side-by-side
server/controllers/auth.controller.js
View file @
9e604666
...
...
@@ -8,8 +8,7 @@ const login = async (req, res) => {
console
.
log
(
req
.
body
)
try
{
const
user
=
await
User
.
findOne
({
role
:
"
user
"
,
id
:
id
}).
select
(
'
password name
'
)
const
user
=
await
User
.
findOne
({
id
}).
select
(
'
password role name tel email
'
)
console
.
log
(
'
u=
'
,
user
)
if
(
!
user
)
{
return
res
.
status
(
404
).
send
(
`
${
user
.
id
}
가 존재하지 않습니다.`
)
...
...
@@ -24,7 +23,7 @@ const login = async (req, res) => {
httpOnly
:
true
,
secure
:
config
.
env
===
'
production
'
})
res
.
json
({
userId
:
user
.
_id
,
role
:
user
.
role
,
name
:
user
.
name
})
res
.
json
({
userId
:
user
.
_id
,
role
:
user
.
role
,
name
:
user
.
name
,
tel
:
user
.
tel
,
email
:
user
.
email
})
}
else
{
res
.
status
(
401
).
send
(
'
비밀번호가 일치하지 않습니다.
'
)
...
...
server/controllers/cart.controller.js
View file @
9e604666
import
Cart
from
"
../schemas/Cart.js
"
;
const
add
c
art
=
async
(
req
,
res
)
=>
{
const
{
userId
,
products
}
=
req
.
body
const
add
C
art
=
async
(
req
,
res
)
=>
{
const
{
userId
,
products
}
=
req
.
body
try
{
const
cart
=
await
Cart
.
findOne
({
userId
:
userId
})
await
Cart
.
updateOne
(
{
_id
:
cart
.
_id
},
{
$set
:
{
products
:
products
}
}
{
$push
:
{
products
:
products
}
}
)
res
.
status
(
200
).
send
(
'
카트에 저장되었습니다.
'
)
}
catch
(
error
)
{
...
...
@@ -15,11 +15,26 @@ const addcart = async (req, res) => {
}
}
const
showcart
=
async
(
req
,
res
)
=>
{
const
changeCart
=
async
(
req
,
res
)
=>
{
const
{
userId
,
products
}
=
req
.
body
console
.
log
(
products
)
try
{
const
cart
=
await
Cart
.
findOne
({
userId
:
userId
})
await
Cart
.
updateOne
(
{
_id
:
cart
.
_id
},
{
$set
:
{
products
:
products
}
}
)
res
.
send
(
"
카트에 체크가 활성화되었습니다
"
)
}
catch
(
error
)
{
res
.
send
(
"
카트 체인지 실패
"
)
}
}
const
showCart
=
async
(
req
,
res
)
=>
{
try
{
const
cart
=
await
Cart
.
findOne
({
userId
:
req
.
id
}).
populate
({
path
:
'
products.productId
'
,
model
:
'
Product
'
model
:
'
Product
'
})
res
.
status
(
200
).
json
(
cart
.
products
)
}
catch
(
error
)
{
...
...
@@ -28,18 +43,48 @@ const showcart = async (req, res) => {
}
}
const
delete
c
art
=
async
(
req
,
res
)
=>
{
const
delete
C
art
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
const
{
cartId
}
=
req
.
body
const
{
userId
,
cartId
}
=
req
.
body
try
{
await
Cart
.
deleteOne
({
_id
:
cartId
})
res
.
send
(
"
삭제완료
"
)
const
cart
=
await
Cart
.
findOneAndUpdate
(
{
userId
:
userId
},
{
$pull
:
{
products
:
{
_id
:
cartId
}
}
},
{
new
:
true
}
).
populate
({
path
:
'
products.productId
'
,
model
:
'
Product
'
})
res
.
json
(
cart
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
해당 카트를 삭제하지 못했습니다.
'
)
}
}
const
deleteCart2
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
const
{
userId
,
cartId
}
=
req
.
body
try
{
for
(
let
i
=
0
;
i
<
cartId
.
length
;
i
++
){
await
Cart
.
findOneAndUpdate
(
{
userId
:
userId
},
{
$pull
:
{
products
:
{
_id
:
cartId
[
i
]
}
}
},
{
new
:
true
}
).
populate
({
path
:
'
products.productId
'
,
model
:
'
Product
'
})
}
res
.
send
(
"
주문완료 및 쇼핑카트에서 삭제
"
)
// res.json(cart)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
해당 카트를 삭제하지 못했습니다.
'
)
}
}
const
userById
=
async
(
req
,
res
,
next
,
id
)
=>
{
try
{
const
cart
=
await
Cart
.
findOne
({
userId
:
id
})
...
...
@@ -55,4 +100,4 @@ const userById = async (req, res, next, id) => {
}
export
default
{
addcart
,
showcart
,
deletecart
,
userById
}
\ No newline at end of file
export
default
{
addCart
,
changeCart
,
showCart
,
deleteCart
,
deleteCart2
,
userById
}
\ No newline at end of file
server/controllers/category.controller.js
View file @
9e604666
import
Category
from
"
../schemas/Category.js
"
;
const
getCategory
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
dsadd=
"
)
try
{
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
const
category
=
await
Category
.
find
({},
{
_id
:
0
})
// console.log("main= ", category);
res
.
json
(
category
)
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
@@ -11,15 +11,60 @@ const getCategory = async (req, res) => {
}
}
// const getSubCategory=(req,res)=>{
// }
const
getSubCategory
=
async
(
req
,
res
)
=>
{
// console.log("req.params=", req.params);
const
{
sub
}
=
req
.
params
try
{
const
subcategory
=
await
Category
.
findOne
({},
{
_id
:
0
}).
select
(
`
${
sub
}
`
)
// console.log("sub= ",subcategory);
res
.
json
(
subcategory
);
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
}
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
{
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
// const getsubId=(req,res,next,sub)=>{
// console.log('sub=',sub)
const
getsubId
=
async
(
req
,
res
,
next
,
ele
)
=>
{
try
{
const
sub
=
await
Category
.
find
({
ele
})
if
(
!
sub
)
{
res
.
status
(
404
).
send
(
'
카테고리가 존재하지 않습니다.
'
)
}
req
.
category
=
sub
req
.
subcategory
=
sub
next
()
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
status
(
500
).
send
(
'
카테고리를 불러오지 못했습니다.
'
)
}
next
()
}
// next()
// const userById = async (req, res, next, id) => {
// try {
// const user = await User.findById(id)
// if (!user) {
// res.status(404).send('사용자를 찾을 수 없습니다')
// }
// req.account = user
// next()
// } catch (error) {
// console.log(error);
// res.status(500).send('사용자 아이디 검색 실패')
// }
// }
export
default
{
getCategory
}
\ No newline at end of file
export
default
{
getCategory
,
getsubId
,
getSubCategory
,
getToHome
}
server/controllers/order.controller.js
0 → 100644
View file @
9e604666
import
Order
from
"
../schemas/Order.js
"
;
import
User
from
"
../schemas/User.js
"
;
const
addorder
=
async
(
req
,
res
)
=>
{
const
{
userId
,
products
,
receiverInfo
,
total
}
=
req
.
body
try
{
const
newOrder
=
await
new
Order
({
userId
,
products
,
receiverInfo
,
total
}).
save
()
res
.
status
(
200
).
send
(
'
Order DB에 저장 완료
'
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
Order DB에 저장 실패
'
)
}
}
const
showorder
=
async
(
req
,
res
)
=>
{
try
{
const
order
=
await
Order
.
find
({
userId
:
req
.
userId
}).
sort
({
_id
:
-
1
}).
limit
(
1
).
populate
({
path
:
'
products.productId
'
,
model
:
'
Product
'
})
console
.
log
(
order
)
res
.
status
(
200
).
json
(
order
[
0
])
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
쇼핑카트를 불러오지 못했습니다.
'
)
}
}
const
orderById
=
async
(
req
,
res
,
next
,
id
)
=>
{
try
{
const
user
=
await
User
.
findById
(
id
)
if
(
!
user
)
{
res
.
status
(
404
).
send
(
'
사용자를 찾을 수 없습니다
'
)
}
req
.
userId
=
user
next
()
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
status
(
500
).
send
(
'
사용자 아이디 검색 실패
'
)
}
}
export
default
{
addorder
,
showorder
,
orderById
}
\ No newline at end of file
server/controllers/product.controller.js
View file @
9e604666
...
...
@@ -29,29 +29,25 @@ const regist = async (req, res) => {
}
}
const
getToHome
=
async
(
re
s
,
re
q
)
=>
{
const
getToHome
=
async
(
re
q
,
re
s
)
=>
{
try
{
const
bestProduct
=
await
Product
.
find
({}).
sort
({
purchase
:
1
}).
limit
(
6
)
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
)
//
console.log("best=", bestProduct)
//
console.log("new=", newProduct)
res
.
json
(
{
bestProduct
,
newProduct
}
)
}
catch
{
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
const
Sortlist
=
async
(
re
s
,
re
q
)
=>
{
const
getAll
=
async
(
re
q
,
re
s
)
=>
{
try
{
const
newlist
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
})
const
bestlist
=
await
Product
.
find
({}).
sort
({
purchase
:
1
})
console
.
log
(
'
bestsort
'
,
bestlist
)
console
.
log
(
'
newlist
'
,
newlist
)
res
.
json
(
newlist
,
bestlist
)
}
catch
{
const
productslist
=
await
Product
.
find
({}).
sort
({
createdAt
:
-
1
})
res
.
json
(
productslist
)
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
const
getlist
=
(
req
,
res
)
=>
{
...
...
@@ -62,7 +58,6 @@ const getlist = (req, res) => {
}
}
const
categoryId
=
async
(
req
,
res
,
next
,
category
)
=>
{
try
{
const
productslist
=
await
Product
.
find
({
main_category
:
category
})
...
...
@@ -83,6 +78,7 @@ const subgetlist = (req, res) => {
res
.
status
(
500
).
send
(
'
상품을 불러오지 못했습니다.
'
)
}
}
const
subcategoryId
=
async
(
req
,
res
,
next
,
subcategory
)
=>
{
try
{
const
subproductslist
=
await
Product
.
find
({
sub_category
:
subcategory
})
...
...
@@ -96,4 +92,32 @@ const subcategoryId = async (req, res, next, subcategory) => {
}
}
export
default
{
imageUpload
,
regist
,
categoryId
,
getlist
,
subcategoryId
,
subgetlist
,
getToHome
,
Sortlist
}
const
plusPurchase
=
async
(
req
,
res
)
=>
{
const
{
products
}
=
req
.
body
// console.log(products)
try
{
for
(
let
i
=
0
;
i
<
products
.
length
;
i
++
)
{
const
count
=
products
[
i
].
count
const
product
=
await
Product
.
findOne
(
{
_id
:
products
[
i
].
productId
.
_id
}
)
const
purchase
=
product
.
purchase
const
stock
=
product
.
stock
await
Product
.
updateOne
(
{
_id
:
products
[
i
].
productId
.
_id
},
{
$set
:
{
purchase
:
count
+
purchase
,
stock
:
stock
-
count
}
}
)
// console.log("i=", i)
}
res
.
send
(
"
구매수 늘리기, 재고수 줄이기 성공
"
)
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
구매숫자를 늘리지 못함
'
)
}
}
export
default
{
imageUpload
,
regist
,
getToHome
,
getAll
,
categoryId
,
getlist
,
subcategoryId
,
subgetlist
,
plusPurchase
}
server/controllers/user.controller.js
View file @
9e604666
...
...
@@ -31,10 +31,8 @@ const userById = async (req, res, next, id) => {
const
signup
=
async
(
req
,
res
)
=>
{
const
{
name
,
number1
,
number2
,
id
,
password
,
tel
}
=
req
.
body
console
.
log
(
req
.
body
)
const
{
name
,
number1
,
number2
,
id
,
password
,
tel
,
email
}
=
req
.
body
console
.
log
(
"
whatup
"
,
req
.
body
)
try
{
if
(
!
isLength
(
password
,
{
min
:
8
,
max
:
15
}))
{
return
res
.
status
(
422
).
send
(
'
비밀번호는 8-15자리로 입력해주세요.
'
)
...
...
@@ -53,8 +51,9 @@ const signup = async (req, res) => {
id
,
password
:
hash
,
tel
,
email
}).
save
()
await
new
Cart
({
userId
:
newUser
.
_id
,
role
}).
save
()
await
new
Cart
({
userId
:
newUser
.
_id
}).
save
()
console
.
log
(
newUser
)
res
.
json
(
newUser
)
...
...
@@ -79,7 +78,7 @@ const update = async (req, res) => {
const
updateUser
=
await
user
.
save
()
res
.
json
(
updateUser
)
}
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
status
(
500
).
send
(
'
이미지 업데이트 실패
'
)
...
...
server/routes/cart.routes.js
View file @
9e604666
...
...
@@ -5,15 +5,20 @@ import cartCtrl from '../controllers/cart.controller.js';
const
router
=
express
.
Router
()
router
.
route
(
'
/addcart
'
)
.
put
(
cartCtrl
.
add
c
art
)
.
put
(
cartCtrl
.
add
C
art
)
// .get()
router
.
route
(
'
/showcart/:userId
'
)
.
get
(
cartCtrl
.
showcart
)
router
.
param
(
'
userId
'
,
cartCtrl
.
userById
)
.
get
(
cartCtrl
.
showCart
)
router
.
route
(
'
/changecart
'
)
.
post
(
cartCtrl
.
changeCart
)
router
.
route
(
'
/deletecart
'
)
.
post
(
cartCtrl
.
deletecart
)
.
post
(
cartCtrl
.
deleteCart
)
router
.
route
(
'
/deletecart2
'
)
.
post
(
cartCtrl
.
deleteCart2
)
router
.
param
(
'
userId
'
,
cartCtrl
.
userById
)
export
default
router
\ No newline at end of file
server/routes/order.routes.js
0 → 100644
View file @
9e604666
import
express
from
"
express
"
;
import
orderCtrl
from
'
../controllers/order.controller.js
'
;
const
router
=
express
.
Router
()
router
.
route
(
'
/addorder
'
)
.
post
(
orderCtrl
.
addorder
)
// .get()
router
.
route
(
'
/showorder/:userId
'
)
.
get
(
orderCtrl
.
showorder
)
router
.
param
(
'
userId
'
,
orderCtrl
.
orderById
)
export
default
router
\ No newline at end of file
server/routes/product.routes.js
View file @
9e604666
...
...
@@ -13,14 +13,19 @@ router.route('/regist')
router
.
route
(
'
/getproduct
'
)
.
get
(
productCtrl
.
getToHome
)
router
.
route
(
'
/getproduct/all
'
)
.
get
(
productCtrl
.
getAll
)
router
.
route
(
'
/getproduct/:category
'
)
.
get
(
productCtrl
.
getlist
)
router
.
route
(
'
/getproduct/:subcategory
'
)
.
get
(
productCtrl
.
subgetlist
)
router
.
param
(
'
category
'
,
productCtrl
.
categoryId
)
router
.
route
(
'
/pluspurchase
'
)
.
post
(
productCtrl
.
plusPurchase
)
router
.
param
(
'
category
'
,
productCtrl
.
categoryId
)
router
.
param
(
'
subcategory
'
,
productCtrl
.
subcategoryId
)
export
default
router
\ No newline at end of file
server/routes/user.routes.js
View file @
9e604666
...
...
@@ -10,8 +10,6 @@ router.route('/account/:userId')
.
get
(
userCtrl
.
username
)
.
put
(
userCtrl
.
imgUpload
,
userCtrl
.
update
)
router
.
param
(
'
userId
'
,
userCtrl
.
userById
)
export
default
router
\ No newline at end of file
server/schemas/Cart.js
View file @
9e604666
...
...
@@ -17,11 +17,14 @@ const CartSchema = new mongoose.Schema({
type
:
ObjectId
,
ref
:
'
Product
'
},
size
s
:
{
size
:
{
type
:
String
},
color
s
:
{
color
:
{
type
:
String
},
checked
:
{
type
:
Boolean
}
}
]
...
...
server/schemas/Order.js
0 → 100644
View file @
9e604666
import
mongoose
from
'
mongoose
'
const
{
ObjectId
,
Number
,
String
}
=
mongoose
.
Schema
.
Types
const
OrderSchema
=
new
mongoose
.
Schema
({
userId
:
{
type
:
ObjectId
,
ref
:
'
User
'
},
products
:
[
{
productId
:
{
type
:
ObjectId
,
ref
:
'
Product
'
},
count
:
{
type
:
Number
,
required
:
true
},
size
:
{
type
:
String
,
required
:
true
},
color
:
{
type
:
String
,
required
:
true
},
checked
:
{
type
:
Boolean
}
}
],
receiverInfo
:
{
name
:
{
type
:
String
,
required
:
true
},
tel
:
{
type
:
String
,
required
:
true
},
postalCode
:
{
type
:
String
,
required
:
true
},
address
:
{
type
:
String
,
required
:
true
},
address2
:
{
type
:
String
,
required
:
true
}
}
,
total
:
{
type
:
Number
,
required
:
true
}
},
{
timestamps
:
true
})
export
default
mongoose
.
models
.
Order
||
mongoose
.
model
(
'
Order
'
,
OrderSchema
)
\ No newline at end of file
server/schemas/Product.js
View file @
9e604666
import
mongoose
from
'
mongoose
'
const
{
String
,
Number
}
=
mongoose
.
Schema
.
Types
const
{
String
,
Array
,
Number
}
=
mongoose
.
Schema
.
Types
const
ProductSchema
=
new
mongoose
.
Schema
({
pro_name
:
{
...
...
@@ -21,11 +21,11 @@ const ProductSchema = new mongoose.Schema({
default
:
0
},
sizes
:
{
type
:
Array
,
type
:
[
String
]
,
required
:
true
},
colors
:
{
type
:
Array
,
type
:
[
String
]
,
required
:
true
},
main_category
:
{
...
...
@@ -33,7 +33,7 @@ const ProductSchema = new mongoose.Schema({
required
:
true
,
},
sub_category
:
{
type
:
[
String
]
,
type
:
Array
,
required
:
true
,
},
description
:
{
...
...
@@ -45,7 +45,7 @@ const ProductSchema = new mongoose.Schema({
required
:
true
},
detail_imgUrls
:
{
type
:
[
String
]
type
:
Array
}
},
{
timestamps
:
true
...
...
server/schemas/User.js
View file @
9e604666
...
...
@@ -34,6 +34,10 @@ const UserSchema = new mongoose.Schema({
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
},
email
:
{
type
:
String
,
required
:
true
,
},
avatarUrl
:
{
type
:
String
}
...
...
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