Commit 5eda65e7 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

Merge remote-tracking branch 'origin/cherry' into rkyoung7

parents a70c295a 82e884ab
......@@ -28,8 +28,10 @@ function Menu() {
}, [])
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
.then(res => {
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
}).then(res => {
console.log(res.data)
if (res.data.role == "admin") {
setUser(res.data)
}
......@@ -59,12 +61,12 @@ function Menu() {
}} className="nav-link">
대관 확인/취소</NavLink>
{user.role === "admin" ? (
{/* {user.role === "admin" ? (
<NavLink as={Link} to={{
pathname: `/acheck/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">
대관 확인/취소(관리자)</NavLink>) : null}
대관 확인/취소(관리자)</NavLink>) : null} */}
</Nav>
<Nav >
<NavLink>
......
......@@ -26,18 +26,9 @@ function ACheck(props) {
alert(err.error)
});
}
if (state) return <Redirect to="/home" />;
if (state) return <Redirect to="/" />;
function remove(index) {
// axios.delete(`/reserves/${reserve[index]._id}`)
// .then(res => {
// if (res.status === 404) return alert(res.data.error)
// alert("삭제되었습니다!");
// getReserve();
// })
// .catch(err => {
// alert(err.error)
// });
axios.put(`/reserves/${reserve[index]._id}`)
.then(res => {
if (res.status === 404) return alert(res.data.error)
......
......@@ -7,14 +7,14 @@ import { Redirect } from 'react-router-dom';
import { Col, Container, Row } from 'react-bootstrap';
function Apply(props) {
const [state, setState] = useState();
const [state, setState] = useState({ok:""});
const [user, setUser] = useState({ name: "" });
useEffect(() => {
getUser();
}, [])
if (state) {
if (state.ok==="no") return <Redirect to="/" />;
if (state.ok==="ok") {
return <Redirect to={{
pathname: `/check/${props.match.params.id}`,
state: { id: props.match.params.id },
......@@ -50,6 +50,8 @@ function Apply(props) {
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState({ok:"no"});
}
console.log(res.data);
setUser(res.data);
......@@ -97,7 +99,7 @@ function Apply(props) {
return window.location.reload();
}
alert("신청이 완료되었습니다!");
setState(true);
setState({ok:"ok"});
console.log("res.data", res.data)
})
.catch(err => {
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import { Redirect } from 'react-router-dom';
import axios from 'axios';
function Check(props) {
const [reserve, setReserve] = useState([]);
const [state, setState] = useState()
useEffect(() => {
getReserve();
}, [])
if (state) return <Redirect to="/" />;
function getReserve() {
axios.get(`/reserves/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
if (res.status === 404) {
alert(res.data.error);
}
if (res.status === 419) {
alert(res.data.error);
localStorage.clear();
setState(true);
}
console.log(res.data);
setReserve(res.data);
const reserves=res.data.filter(function(item) {
return item !== '';
});
setReserve(reserves);
})
.catch(err => {
alert(err.error)
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import Schedule from '../Components/Schedule';
import { Redirect } from 'react-router-dom';
import Tabs from 'react-bootstrap/Tabs';
import axios from 'axios';
import Tab from 'react-bootstrap/Tab';
function Home() {
const [key, setKey] = useState('9-116');
const [state, setState] = useState()
useEffect(() => {
tcheck();
}, []);
if (state) return <Redirect to="/" />;
function tcheck() {
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState(true);
}
}).catch(err => {
alert(err.error)
});
}
return (
<div>
......@@ -21,13 +45,13 @@ function Home() {
</p>
<Tabs defaultActiveKey="9-116" id="uncontrolled-tab-example" onSelect={(k) => setKey(k)}>
<Tab eventKey="9-116" title="9-116">
<Schedule room={key}/>
<Schedule room={key} />
</Tab>
<Tab eventKey="7-234" title="7-234">
<Schedule room={key}/>
<Schedule room={key} />
</Tab>
<Tab eventKey="25-101" title="25-101">
<Schedule room={key}/>
<Schedule room={key} />
</Tab>
</Tabs>
<h3>유의사항</h3>
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import axios from 'axios';
import { Link } from 'react-router-dom';
import { Link, Redirect } from 'react-router-dom';
import { Container, Row, Col, Card, Accordion, Button } from 'react-bootstrap';
function Notice() {
const [show, setShow] = useState(false);
const [notices, setNotices] = useState([]);
const [user, setUser] = useState({ role: "" })
const [state, setState] = useState()
useEffect(() => {
acheck();
getNotice();
}, []);
if (state) return <Redirect to="/" />;
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState(true);
}
if (res.data.role == "admin") {
setUser(res.data)
}
......
......@@ -37,7 +37,7 @@ router.post('/', function (req, res, next) {
const token = jwt.sign({
id: users.id,
}, process.env.JWT_SECRET, {
expiresIn: '1m',
expiresIn: '1h',
});
return res.status(201).json({
token,
......
......@@ -17,7 +17,8 @@ router.post('/', function (req, res, next) {
room: req.body.room,
reason: req.body.reason,
students: req.body.students,
approve: req.body.approve,
approve: true,
check: true,
num: req.body.students.length + 1,
});
......@@ -70,15 +71,25 @@ router.get('/room/:room', function (req, res, next) {
})
// router.get('/:_id', verifyToken, function (req, res, next) {
router.get('/:_id', function (req, res, next) {
router.get('/:_id', verifyToken, function (req, res, next) {
console.log('/reserves get req.params', req.params)
Reserve.find({ user: req.params._id }, function (err, reserve) {
if (err) return res.status(500).json({ error: err });
res.status(201).json(reserve);
// console.log(reserve, Date.now())
const reserves = reserve.map(item => (
new Date(item.end) >= Date.now() ? item : ""
));
if (!reserves) {
console.log("no신청")
res.status(404).json({error: "신청내역이 없습니다."})
}
console.log("reserves",reserves)
res.status(201).json(reserves);
})
});
router.get('/admin/:_id', function (req, res, next) {
router.get('/admin/:_id', verifyToken, function (req, res, next) {
console.log('/reserves/admin get req.params', req.params)
Reserve.find({ approve: false }).populate('user').exec(function (err, reserve) {
if (err) return res.status(500).json({ error: err });
......
......@@ -34,7 +34,7 @@ router.post('/', function (req, res, next) {
})
});
router.get('/:_id', function (req, res, next) {
router.get('/:_id', verifyToken, function (req, res, next) {
console.log('/users get req.params', req.params)
User.findOne({ _id: req.params._id }, function (err, user) {
if (err) return res.status(500).json({ error: err });
......
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