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
df51efcd
Commit
df51efcd
authored
Jan 13, 2021
by
이재연
Browse files
Merge remote-tracking branch 'origin/ourMaster' into jaeyeon
parents
98bc3e3a
e7e1d3d1
Changes
27
Show whitespace changes
Inline
Side-by-side
client/src/utils/catchErrors.js
View file @
df51efcd
function
catchErrors
(
error
,
displayError
)
{
function
catchErrors
(
error
,
displayError
)
{
let
errorMsg
let
errorMsg
if
(
error
.
response
){
if
(
error
.
response
)
{
errorMsg
=
error
.
response
.
data
errorMsg
=
error
.
response
.
data
console
.
log
(
errorMsg
)
console
.
log
(
errorMsg
)
}
else
if
(
error
.
request
){
}
else
if
(
error
.
request
)
{
errorMsg
=
error
.
request
errorMsg
=
error
.
request
console
.
log
(
errorMsg
)
console
.
log
(
errorMsg
)
}
else
{
}
else
{
errorMsg
=
error
.
message
errorMsg
=
error
.
message
console
.
log
(
errorMsg
)
console
.
log
(
errorMsg
)
}
}
displayError
(
errorMsg
)
displayError
(
errorMsg
)
...
...
server/app.js
View file @
df51efcd
import
express
from
'
express
'
;
import
express
from
'
express
'
;
//
import
bodyParser from "body-parser"
;
import
fs
from
'
fs
'
;
import
connectDb
from
'
./schemas/index.js
'
import
connectDb
from
'
./schemas/index.js
'
import
userRouter
from
"
./routes/user.routes.js
"
;
import
userRouter
from
"
./routes/user.routes.js
"
;
import
productRouter
from
'
./routes/product.routes.js
'
;
import
productRouter
from
'
./routes/product.routes.js
'
;
...
@@ -10,14 +10,17 @@ import config from './config.js'
...
@@ -10,14 +10,17 @@ import config from './config.js'
import
authRouter
from
'
./routes/auth.routes.js
'
import
authRouter
from
'
./routes/auth.routes.js
'
import
cors
from
'
cors
'
import
cors
from
'
cors
'
fs
.
readdir
(
'
uploads
'
,
(
error
)
=>
{
if
(
error
)
{
fs
.
mkdirSync
(
'
uploads
'
);
}
})
connectDb
()
connectDb
()
const
app
=
express
();
const
app
=
express
();
app
.
use
(
express
.
json
());
app
.
use
(
cors
())
app
.
use
(
cors
())
app
.
use
(
express
.
static
(
path
.
join
(
process
.
cwd
(),
'
dist
'
)))
app
.
use
(
express
.
static
(
path
.
join
(
process
.
cwd
(),
'
dist
'
)))
// app.use(bodyParser.urlencoded({ extended: true }))
// app.use(bodyParser.urlencoded({ extended: true }))
...
...
server/controllers/product.controller.js
View file @
df51efcd
import
Product
from
"
../schemas/Product.js
"
;
import
Product
from
"
../schemas/Product.js
"
;
import
multer
from
'
multer
'
;
const
upload
=
multer
({
dest
:
'
uploads/
'
})
const
imageUpload
=
upload
.
fields
([
{
name
:
'
main_image
'
},
{
name
:
'
detail_image
'
}
])
const
regist
=
async
(
req
,
res
)
=>
{
const
regist
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
req.body=
'
,
req
.
body
)
const
{
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
,
main_image
,
detail_image
}
=
req
.
body
try
{
try
{
const
newProduct
=
await
new
Product
({
const
{
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
}
=
req
.
body
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
,
main_image
,
detail_image
const
main_img
=
req
.
files
[
'
main_image
'
][
0
]
const
detail_img
=
req
.
files
[
'
detail_image
'
]
const
main_imgUrl
=
main_img
.
filename
const
detail_imgUrls
=
[]
detail_img
.
forEach
(
file
=>
{
detail_imgUrls
.
push
(
file
.
filename
)
})
const
newProduct
=
await
new
Product
({
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
,
main_imgUrl
,
detail_imgUrls
}).
save
()
}).
save
()
res
.
json
(
newProduct
)
res
.
json
(
newProduct
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
죄송합
니다. 다시
입력
해 주십시오.
'
)
res
.
status
(
500
).
send
(
'
제품 정보 등록에 실패하였습
니다. 다시
진행
해 주십시오.
'
)
}
}
}
}
export
default
{
regist
}
export
default
{
imageUpload
,
regist
}
\ No newline at end of file
\ No newline at end of file
server/controllers/user.controller.js
View file @
df51efcd
import
User
from
"
../schemas/User.js
"
;
import
User
from
"
../schemas/User.js
"
;
import
isLength
from
'
validator/lib/isLength.js
'
import
isLength
from
'
validator/lib/isLength.js
'
;
import
bcrypt
from
'
bcryptjs
'
import
bcrypt
from
'
bcryptjs
'
;
const
signup
=
async
(
req
,
res
)
=>
{
const
signup
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
console
.
log
(
req
.
body
)
...
@@ -14,7 +14,6 @@ const signup = async (req, res) => {
...
@@ -14,7 +14,6 @@ const signup = async (req, res) => {
return
res
.
status
(
422
).
send
(
`
${
id
}
가 이미 사용중입니다.`
)
return
res
.
status
(
422
).
send
(
`
${
id
}
가 이미 사용중입니다.`
)
}
}
const
hash
=
await
bcrypt
.
hash
(
password
,
10
)
const
hash
=
await
bcrypt
.
hash
(
password
,
10
)
const
newUser
=
await
new
User
({
const
newUser
=
await
new
User
({
...
@@ -34,5 +33,4 @@ const signup = async (req, res) => {
...
@@ -34,5 +33,4 @@ const signup = async (req, res) => {
}
}
}
}
export
default
{
signup
}
export
default
{
signup
}
\ No newline at end of file
server/routes/product.routes.js
View file @
df51efcd
import
express
from
"
express
"
;
import
express
from
"
express
"
;
import
path
from
'
path
'
;
import
multer
from
'
multer
'
;
import
productCtrl
from
'
../controllers/product.controller.js
'
;
import
productCtrl
from
'
../controllers/product.controller.js
'
;
import
fs
from
'
fs
'
// process.cwd() + '/client/public/image'
const
router
=
express
.
Router
()
const
router
=
express
.
Router
()
fs
.
readdir
(
'
uploads
'
,
(
error
,
data
)
=>
{
router
.
route
(
'
/regist
'
)
if
(
error
)
{
.
post
(
productCtrl
.
imageUpload
,
productCtrl
.
regist
)
fs
.
mkdirSync
(
'
uploads
'
);
if
(
data
==
undefined
)
{
fs
.
mkdirSync
(
'
/main
'
)
fs
.
mkdirSync
(
'
/detail
'
)
}
}
else
console
.
log
(
"
else data
"
,
data
)
})
const
upload
=
multer
({
// router.route('/productone')
storage
:
multer
.
diskStorage
({
// .get(productCtrl.getProduct)
destination
(
req
,
file
,
cb
)
{
cb
(
null
,
'
uploads/
'
);
},
// 저장 경로 변경
filename
(
req
,
file
,
cb
)
{
cb
(
null
,
new
Date
().
valueOf
()
+
path
.
extname
(
file
.
originalname
));
},
// 파일명 변경
}),
});
router
.
route
(
'
/regist
'
)
.
post
(
productCtrl
.
regist
)
// upload.array('main_image'),
export
default
router
export
default
router
\ No newline at end of file
server/schemas/Product.js
View file @
df51efcd
import
mongoose
from
'
mongoose
'
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
,
Number
}
=
mongoose
.
Schema
.
Types
const
ProductSchema
=
new
mongoose
.
Schema
({
const
ProductSchema
=
new
mongoose
.
Schema
({
pro_name
:
{
pro_name
:
{
...
@@ -20,11 +20,11 @@ const ProductSchema = new mongoose.Schema({
...
@@ -20,11 +20,11 @@ const ProductSchema = new mongoose.Schema({
required
:
true
,
required
:
true
,
default
:
0
default
:
0
},
},
size
:
{
size
s
:
{
type
:
Array
,
type
:
Array
,
required
:
true
required
:
true
},
},
color
:
{
color
s
:
{
type
:
Array
,
type
:
Array
,
required
:
true
required
:
true
},
},
...
@@ -33,20 +33,19 @@ const ProductSchema = new mongoose.Schema({
...
@@ -33,20 +33,19 @@ const ProductSchema = new mongoose.Schema({
required
:
true
,
required
:
true
,
},
},
sub_category
:
{
sub_category
:
{
type
:
Array
,
type
:
[
String
]
,
required
:
true
,
required
:
true
,
},
},
description
:
{
description
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
main_im
age
:
{
main_im
gUrl
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
},
},
detail_image
:
{
detail_imgUrls
:
{
type
:
String
,
type
:
[
String
]
required
:
true
,
}
}
},
{
},
{
timestamps
:
true
timestamps
:
true
...
...
server/schemas/User.js
View file @
df51efcd
...
@@ -16,7 +16,6 @@ const UserSchema = new mongoose.Schema({
...
@@ -16,7 +16,6 @@ const UserSchema = new mongoose.Schema({
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
number1
:
{
number1
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
...
...
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