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
Hide whitespace changes
Inline
Side-by-side
client/src/utils/catchErrors.js
View file @
df51efcd
function
catchErrors
(
error
,
displayError
)
{
function
catchErrors
(
error
,
displayError
)
{
let
errorMsg
if
(
error
.
response
){
errorMsg
=
error
.
response
.
data
if
(
error
.
response
)
{
errorMsg
=
error
.
response
.
data
console
.
log
(
errorMsg
)
}
else
if
(
error
.
request
){
errorMsg
=
error
.
request
}
else
if
(
error
.
request
)
{
errorMsg
=
error
.
request
console
.
log
(
errorMsg
)
}
else
{
errorMsg
=
error
.
message
}
else
{
errorMsg
=
error
.
message
console
.
log
(
errorMsg
)
}
displayError
(
errorMsg
)
}
export
default
catchErrors
export
default
catchErrors
\ No newline at end of file
server/app.js
View file @
df51efcd
import
express
from
'
express
'
;
//
import
bodyParser from "body-parser"
;
import
fs
from
'
fs
'
;
import
connectDb
from
'
./schemas/index.js
'
import
userRouter
from
"
./routes/user.routes.js
"
;
import
productRouter
from
'
./routes/product.routes.js
'
;
...
...
@@ -10,14 +10,17 @@ import config from './config.js'
import
authRouter
from
'
./routes/auth.routes.js
'
import
cors
from
'
cors
'
fs
.
readdir
(
'
uploads
'
,
(
error
)
=>
{
if
(
error
)
{
fs
.
mkdirSync
(
'
uploads
'
);
}
})
connectDb
()
const
app
=
express
();
app
.
use
(
express
.
json
());
app
.
use
(
cors
())
app
.
use
(
express
.
static
(
path
.
join
(
process
.
cwd
(),
'
dist
'
)))
// app.use(bodyParser.urlencoded({ extended: true }))
...
...
server/controllers/product.controller.js
View file @
df51efcd
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
)
=>
{
console
.
log
(
'
req.body=
'
,
req
.
body
)
const
{
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
,
main_image
,
detail_image
}
=
req
.
body
try
{
const
newProduct
=
await
new
Product
({
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
,
main_image
,
detail_image
const
{
pro_name
,
price
,
stock
,
main_category
,
sub_category
,
description
}
=
req
.
body
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
()
res
.
json
(
newProduct
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
죄송합
니다. 다시
입력
해 주십시오.
'
)
res
.
status
(
500
).
send
(
'
제품 정보 등록에 실패하였습
니다. 다시
진행
해 주십시오.
'
)
}
}
export
default
{
regist
}
\ No newline at end of file
export
default
{
imageUpload
,
regist
}
\ No newline at end of file
server/controllers/user.controller.js
View file @
df51efcd
import
User
from
"
../schemas/User.js
"
;
import
isLength
from
'
validator/lib/isLength.js
'
import
bcrypt
from
'
bcryptjs
'
import
isLength
from
'
validator/lib/isLength.js
'
;
import
bcrypt
from
'
bcryptjs
'
;
const
signup
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
...
...
@@ -13,7 +13,6 @@ const signup = async (req, res) => {
if
(
user
){
return
res
.
status
(
422
).
send
(
`
${
id
}
가 이미 사용중입니다.`
)
}
const
hash
=
await
bcrypt
.
hash
(
password
,
10
)
...
...
@@ -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
path
from
'
path
'
;
import
multer
from
'
multer
'
;
import
productCtrl
from
'
../controllers/product.controller.js
'
;
import
fs
from
'
fs
'
// process.cwd() + '/client/public/image'
const
router
=
express
.
Router
()
fs
.
readdir
(
'
uploads
'
,
(
error
,
data
)
=>
{
if
(
error
)
{
fs
.
mkdirSync
(
'
uploads
'
);
if
(
data
==
undefined
)
{
fs
.
mkdirSync
(
'
/main
'
)
fs
.
mkdirSync
(
'
/detail
'
)
}
}
else
console
.
log
(
"
else data
"
,
data
)
})
const
upload
=
multer
({
storage
:
multer
.
diskStorage
({
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'),
.
post
(
productCtrl
.
imageUpload
,
productCtrl
.
regist
)
// router.route('/productone')
// .get(productCtrl.getProduct)
export
default
router
\ No newline at end of file
server/schemas/Product.js
View file @
df51efcd
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
,
Number
}
=
mongoose
.
Schema
.
Types
const
ProductSchema
=
new
mongoose
.
Schema
({
pro_name
:
{
...
...
@@ -20,11 +20,11 @@ const ProductSchema = new mongoose.Schema({
required
:
true
,
default
:
0
},
size
:
{
size
s
:
{
type
:
Array
,
required
:
true
},
color
:
{
color
s
:
{
type
:
Array
,
required
:
true
},
...
...
@@ -33,20 +33,19 @@ const ProductSchema = new mongoose.Schema({
required
:
true
,
},
sub_category
:
{
type
:
Array
,
type
:
[
String
]
,
required
:
true
,
},
description
:
{
type
:
String
,
required
:
true
,
},
main_im
age
:
{
main_im
gUrl
:
{
type
:
String
,
required
:
true
,
required
:
true
},
detail_image
:
{
type
:
String
,
required
:
true
,
detail_imgUrls
:
{
type
:
[
String
]
}
},
{
timestamps
:
true
...
...
server/schemas/User.js
View file @
df51efcd
...
...
@@ -16,7 +16,6 @@ const UserSchema = new mongoose.Schema({
type
:
String
,
required
:
true
,
},
number1
:
{
type
:
String
,
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