Commit 82e884ab authored by CHAERIN KIM's avatar CHAERIN KIM
Browse files

난몰랑

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