Commit 0da1ed33 authored by 이재연's avatar 이재연
Browse files

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

parents 814fb4cf 3ba7cf83
...@@ -2,7 +2,16 @@ const config = { ...@@ -2,7 +2,16 @@ const config = {
env: process.env.NODEENV || 'development', env: process.env.NODEENV || 'development',
port: process.env.PORT || 3001, port: process.env.PORT || 3001,
jwtSecret: process.env.JWT_SECRET || 'My_Secret_Key', jwtSecret: process.env.JWT_SECRET || 'My_Secret_Key',
mongoDbUri: process.env.MONGEDB_URI || 'mongodb://localhost/shopping-mall' mongoDbUri: process.env.MONGEDB_URI || 'mongodb://localhost/shopping-mall',
kakaoAdminKey: 'b2dda7685c5b2990684d813e362cff07'
} }
export default config // const config = {
\ No newline at end of file // port: 3001,
// kakaoAdminKey: 'b2dda7685c5b2990684d813e362cff07',
// }
export default config
// export default config
\ No newline at end of file
// import { RequestHandler } from "express";
import fetch from 'node-fetch'
import config from "../config.js";
const success = (req, res) => {
console.log('kakaopay success route')
console.log('req body:', req.body)
return res.json({
message: 'Success'
})
}
const fail = (req, res) => {
console.log('kakaopay fail route')
console.log('req body:', req.body)
return res.json({
message: 'Failed'
})
}
const cancel = (req, res) => {
console.log('kakaopay cancel route')
console.log('req body:', req.body)
return res.json({
message: 'Canceled'
})
}
const singleTest = async (req, res) => {
console.log("asdaf")
console.log(req.body)
const item = req.body
// set data
const data = []
for (let property in item) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(item[property]);
data.push(encodedKey + "=" + encodedValue);
}
const bodyData = data.join('&') // encode data (application/x-www-form-urlencoded)
const response = await fetch('https://kapi.kakao.com/v1/payment/ready', {
method: 'POST',
headers: {
'Authorization': `KakaoAK ${config.kakaoAdminKey}`,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: bodyData,
})
// console.log(response)
const resp = await response.json()
console.log(resp)
res.json({redirect_url: resp.next_redirect_pc_url})
}
export default {
success,
fail,
cancel,
singleTest,
}
import Product from "../schemas/Product.js";
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.product
try {
const newProduct = await new Product ({
pro_name, price, stock, main_category, sub_category, description, main_image, detail_image
}).save()
console.log(newProduct)
res.json(newProduct)
} catch (error) {
console.log(error)
res.status(500).send('죄송합니다. 다시 입력해 주십시오.')
}
}
export default { regist }
\ No newline at end of file
...@@ -12,9 +12,12 @@ ...@@ -12,9 +12,12 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1", "express": "^4.17.1",
"mongoose": "^5.11.9", "mongoose": "^5.11.9",
"node-fetch": "^2.6.1",
"nodemon": "^2.0.6", "nodemon": "^2.0.6",
"validator": "^13.5.2" "validator": "^13.5.2",
"multer": "^1.4.2"
} }
} }
import express from 'express'
import kakaopayCtrl from '../controllers/kakaopay.controller.js'
const router = express.Router()
router.route('/kakaopay/success')
.get(kakaopayCtrl.success)
router.route('/api/kakaopay/fail')
.get(kakaopayCtrl.fail)
router.route('/api/kakaopay/cancel')
.get(kakaopayCtrl.cancel)
router.route('/api/kakaopay/test/single')
.post(kakaopayCtrl.singleTest)
export default router
import express from "express";
import productCtrl from '../controllers/product.controller.js';
const router = express.Router()
router.route('/regist')
.post(productCtrl.regist)
export default router
\ No newline at end of file
import mongoose from 'mongoose'
const { String, Number, Array } = mongoose.Schema.Types
const ProductSchema = new mongoose.Schema({
pro_name: {
type: String,
required: true,
},
price: {
type: String,
required: true,
},
stock: {
type: String,
required: true
},
purchase: {
type: String,
required: true,
default: 0
},
main_category: {
type: String,
required: true,
},
sub_category: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
main_image: {
type: String,
required: true,
},
detail_image: {
type: String,
required: true,
}
}, {
timestamps: true
})
export default mongoose.models.Product || mongoose.model('Product', ProductSchema)
\ No newline at end of file
import mongoose from 'mongoose'
const { String } = mongoose.Schema.Types
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
id: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true,
select: false
},
confirm_password:{
type: String,
required: true,
select: false
},
phoneNumber: {
type: String,
required: true,
},
role: {
type: String,
required: true,
default: 'user',
enum: ['user', 'admin', 'root']
},
birth: {
type: String,
required: true,
},
sex: {
type: String,
required: true,
}
}, {
timestamps: true
})
export default mongoose.models.User || mongoose.model('User', UserSchema)
\ 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