Commit 333e946e authored by kusang96's avatar kusang96
Browse files

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

parents 0ea2e9c4 ffb8ee80
import React from 'react'
import { Card, Col, Row } from 'react-bootstrap'
function OrderCard(props) {
return (
<Card >
<Card.Title className="font-weight-bold mt-4 text-center"> 주문 현황</Card.Title>
{
props.ordered.map((e) => (
<Card.Body className='m-1'>
{e.products.length > 1 ?
<Card.Header className="font-weight-bold mb-3 text-center" style={{ background: '#F7F3F3' }}>
{e.products[0].productId.pro_name} {e.products.length - 1}
</Card.Header>
: (
<Card.Header className="font-weight-bold mb-3 text-center" style={{ background: '#F7F3F3' }}>
{e.products[0].productId.pro_name}
</Card.Header>)}
<Col>
<Row>
<Card.Text> 주문번호 : <strong>{e._id}</strong> </Card.Text>
</Row>
<Row>
<Card.Text> 결제금액 : <strong>{e.total}</strong> </Card.Text>
</Row>
<Row>
<Card.Text> 배송지 : <strong> {e.receiverInfo.address} - {e.receiverInfo.address2}</strong> </Card.Text>
</Row>
<Row>
<Card.Text> 주문날짜 : <strong> {e.createdAt.substring(0, 10)}</strong> </Card.Text>
</Row>
</Col>
</Card.Body>
)
)
}
</Card>
)
}
export default OrderCard
......@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
import axios from 'axios';
import catchError from '../utils/catchErrors';
import { isAuthenticated } from '../utils/auth';
import OrderCard from '../Components/OrderCard';
const INIT_ACCOUNT = {
name: "",
......@@ -16,8 +17,7 @@ function Account() {
const [proshow, setProshow] = useState(false)
const [error, setError] = useState("")
const userId = isAuthenticated()
const [ordered, setOrdered] = useState('')
const [ordered, setOrdered] = useState([])
async function getUsername(user) {
try {
......@@ -30,7 +30,7 @@ function Account() {
useEffect(() => {
getUsername(userId)
getOrdered(userId)
getOrdered()
}, [userId])
const handleChange = (event) => {
......@@ -78,11 +78,15 @@ function Account() {
}
}
async function getOrdered({}) {
async function getOrdered() {
console.log("object")
try {
const response = await axios.get(`/api/users/addorder`)
setOrdered(response.data)
const response = await axios.post(`/api/users/addorder`, {
userId: userId
})
const a = response.data
setOrdered(a)
console.log("what=", response.data)
} catch (error) {
catchError(error, setError)
}
......@@ -178,40 +182,13 @@ function Account() {
<a href="mailto:shoppingmall_KU@korea.ac.kr">
<small title="메일보내기"> * 문의 : shoppingmall_KU@korea.ac.kr </small>
</a>
{/* 쇼핑몰 문의 메일보내기 */}
</Row>
</Col>
</Row>
</Card>
<Accordion>
<Row className="my-3 px-3">
<Table>
<thead className="text-center" style={{ background: '#F7F3F3' }}>
<tr>
<th scope="col">주문현황</th>
<th scope="col">배송중</th>
<th scope="col">배송완료</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">케이시앵글부츠(SH)</th>
<td>Mark</td>
<td>Otto</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
</tr>
<tr>
<th scope="row">3</th>
<td colspan="2">Larry the Bird</td>
</tr>
</tbody>
</Table>
</Row>
</Accordion>
<Card>
<OrderCard ordered={ordered} />
</Card>
</Container >
)
}
......
......@@ -10,7 +10,6 @@ const INIT_USER = {
id: '',
password: ''
}
function Login() {
const [validated, setValidated] = useState(false);
......@@ -33,7 +32,7 @@ function Login() {
setValidated(true);
try {
setError('')
const response=await axios.post('/api/auth/login', user)
const response = await axios.post('/api/auth/login', user)
handleLogin(response.data)
setSuccess(true)
} catch (error) {
......@@ -43,7 +42,7 @@ function Login() {
if (success) {
alert('로그인 되었습니다.')
window.location.href='/'
window.location.href = '/'
}
return (
......
import axios from 'axios';
import React, { useState, useEffect, useRef } from 'react';
import { Row, Col, Form, Card, Button, Modal, Image } from 'react-bootstrap';
import { Redirect, useHistory } from 'react-router-dom';
import axios from 'axios';
import catchErrors from '../utils/catchErrors';
import { Row, Col, Form, Card, Button, Modal, Image } from 'react-bootstrap';
function Product({ match, location }) {
......
......@@ -136,7 +136,6 @@ function ProductsList({ match }) {
async function handleSubname(e) {
const subname = e.target.name
try {
console.log("first test!!!!!!!!")
const response = await axios.get(`/api/product/getproduct/sub?subname=${subname}`)
console.log("subname response data=", response.data)
setProductlist(response.data)
......
......@@ -5,7 +5,6 @@ import config from '../config.js'
const login = async (req, res) => {
const { id, password } = req.body
console.log(id, password)
try {
const user = await User.findOne({ id }).select('password role name tel email')
console.log('u=', user)
......@@ -13,7 +12,6 @@ const login = async (req, res) => {
return res.status(404).send(`${id}가 존재하지 않습니다.`)
}
const passwordMatch = await bcrypt.compare(password, user.password)
if (passwordMatch) {
const token = jwt.sign({ userId: user._id }, config.jwtSecret, {
expiresIn: '3d'
......@@ -39,4 +37,5 @@ const logout = (req, res) => {
res.send('로그아웃 되었습니다.')
}
export default { login, logout }
\ No newline at end of file
......@@ -54,5 +54,4 @@ const orderById = async (req, res, next, id) => {
}
}
export default { addorder, showorder, orderById , Ordered}
export default { addorder, showorder, orderById , Ordered }
\ No newline at end of file
......@@ -3,6 +3,7 @@ import User from "../schemas/User.js";
import isLength from 'validator/lib/isLength.js';
import bcrypt from 'bcryptjs';
import multer from "multer";
import Order from "../schemas/Order.js";
const uploadimg = multer({ dest: 'uploads/' });
......@@ -85,4 +86,20 @@ const update = async (req, res) => {
}
}
export default { signup, username, imgUpload, userById, update }
\ No newline at end of file
const addorder = async (req, res) => {
const {userId}=req.body
try {
const order = await Order.find({ userId: userId }).populate({
path: 'products.productId',
model: 'Product'
})
console.log("hey", order)
res.status(200).json(order)
} catch (error) {
console.log(error)
res.status(500).send('주문현황을 불러오지 못했습니다.')
}
}
export default { signup, username, imgUpload, userById,update, addorder }
\ No newline at end of file
......@@ -10,6 +10,9 @@ router.route('/account/:userId')
.get(userCtrl.username)
.put(userCtrl.imgUpload, userCtrl.update)
router.route('/addorder')
.post(userCtrl.addorder)
router.param('userId', userCtrl.userById)
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