Commit 011ac7cb authored by Kim, Subin's avatar Kim, Subin
Browse files

정리

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