Commit fdb92c49 authored by 이재연's avatar 이재연
Browse files

Merge remote-tracking branch 'origin/ourMaster' into jaeyeon

parents 78491956 520cf554
...@@ -51,6 +51,7 @@ const getAll = async (req, res) => { ...@@ -51,6 +51,7 @@ const getAll = async (req, res) => {
} }
const getlist = (req, res) => { const getlist = (req, res) => {
console.log('get list')
try { try {
res.json(req.productslist) res.json(req.productslist)
} catch (error) { } catch (error) {
...@@ -58,43 +59,55 @@ const getlist = (req, res) => { ...@@ -58,43 +59,55 @@ const getlist = (req, res) => {
} }
} }
const categoryId = async (req, res, next, category) => { const subname = async (req, res) => {
try { try {
const productslist = await Product.find({ main_category: category }) console.log("last subname::: LET ME SEE")
if (!productslist) { res.json(req.findsubname)
res.status(404).send('상품을 찾을 수 없습니다.')
}
req.productslist = productslist
next()
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
} }
} }
const subgetlist = (req, res) => { const categoryId = async (req, res, next, category) => {
const { search } = req.body
console.log("server search=", search)
try { try {
res.json(req.subproductslist) const productslist = await Product.find({ main_category: category })
// if (!productslist) {
// res.status(404).send('상품을 찾을 수 없습니다.')
// }
req.productslist = productslist
console.log("nononono", req.productslist)
next()
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
} }
} }
const subcategoryId = async (req, res, next, subcategory) => { const subcategoryId = async (req, res, next, subname) => {
try { try {
const subproductslist = await Product.find({ sub_category: subcategory }) console.log("Please===>>>", subname)
if (!subproductslist) { const findSubname = await Product.find({ sub_category: subname })
res.status(404).send('상품을 찾을 수 없습니다.') console.log("findSubname111=", findSubname)
if (!findSubname) {
const findSubname = {
_id: 'nothing',
pro_name: '상품준비중',
price: 0,
main_imgUrl:''
} }
req.subproductslist = subproductslist console.log("findSubname2222=", findSubname)
next() res.send(findSubname)
}
res.send(findSubname)
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.send('상품을 불러오지 못했습니다.')
} }
} }
const plusPurchase = async (req, res) => { const plusPurchase = async (req, res) => {
const { products } = req.body const { products } = req.body
// console.log(products)
try { try {
for (let i = 0; i < products.length; i++) { for (let i = 0; i < products.length; i++) {
const count = products[i].count const count = products[i].count
...@@ -112,7 +125,6 @@ const plusPurchase = async (req, res) => { ...@@ -112,7 +125,6 @@ const plusPurchase = async (req, res) => {
} }
} }
) )
// console.log("i=", i)
} }
res.send("구매수 늘리기, 재고수 줄이기 성공") res.send("구매수 늘리기, 재고수 줄이기 성공")
} catch (error) { } catch (error) {
...@@ -120,4 +132,4 @@ const plusPurchase = async (req, res) => { ...@@ -120,4 +132,4 @@ const plusPurchase = async (req, res) => {
} }
} }
export default { imageUpload, regist, getToHome, getAll, categoryId, getlist, subcategoryId, subgetlist, plusPurchase } export default { imageUpload, regist, getToHome, getAll, categoryId, getlist, subcategoryId, subname, plusPurchase }
...@@ -32,7 +32,7 @@ const userById = async (req, res, next, id) => { ...@@ -32,7 +32,7 @@ const userById = async (req, res, next, id) => {
const signup = async (req, res) => { const signup = async (req, res) => {
const { name, number1, number2, id, password, tel, email } = req.body const { name, number1, number2, id, password, tel, email } = req.body
console.log("whatup",req.body) console.log("whatup", req.body)
try { try {
if (!isLength(password, { min: 8, max: 15 })) { if (!isLength(password, { min: 8, max: 15 })) {
return res.status(422).send('비밀번호는 8-15자리로 입력해주세요.') return res.status(422).send('비밀번호는 8-15자리로 입력해주세요.')
......
...@@ -9,6 +9,4 @@ router.route('/main') ...@@ -9,6 +9,4 @@ router.route('/main')
// router.route('/sub/:sub') // router.route('/sub/:sub')
// .get(categoryCtrl.getSubCategory) // .get(categoryCtrl.getSubCategory)
// router.param('sub',categoryCtrl.getsubId)
export default router export default router
\ No newline at end of file
...@@ -16,16 +16,16 @@ router.route('/getproduct') ...@@ -16,16 +16,16 @@ router.route('/getproduct')
router.route('/getproduct/all') router.route('/getproduct/all')
.get(productCtrl.getAll) .get(productCtrl.getAll)
router.route('/getproduct/:category') router.route('/getproduct/main/:category')
.get(productCtrl.getlist) .get(productCtrl.getlist)
router.route('/getproduct/:subcategory') router.route('/getproduct/sub/:subname')
.get(productCtrl.subgetlist) .get(productCtrl.subname)
router.route('/pluspurchase') router.route('/pluspurchase')
.post(productCtrl.plusPurchase) .post(productCtrl.plusPurchase)
router.param('category', productCtrl.categoryId) router.param('category', productCtrl.categoryId)
router.param('subcategory',productCtrl.subcategoryId) router.param('subname',productCtrl.subcategoryId)
export default router export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment