Commit f3752c81 authored by CHAERIN KIM's avatar CHAERIN KIM
Browse files

관리자페이지-미승인,숨김

parent d910be68
......@@ -12,7 +12,7 @@
"bootstrap": "^4.5.2",
"formik": "^2.1.5",
"jquery": "^3.5.1",
"moment": "^2.29.0",
"moment": "^2.29.1",
"popper.js": "^1.16.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
......
import axios from 'axios';
import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
......@@ -17,8 +18,13 @@ const Nav = styled.nav`
function Menu() {
const [state, setState] = useState()
const [user, setUser] = useState({ role: "" })
const name = localStorage.getItem('name');
useEffect(() => {
acheck();
}, [])
if (state) return <Redirect to="/" />;
function logout() {
......@@ -27,6 +33,17 @@ function Menu() {
setState(true);
}
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
.then(res => {
if (res.data.role == "admin") {
setUser(res.data)
}
}).catch(err => {
alert(err.error)
});
}
return (
<Nav className="navbar sticky-top navbar-expand-md">
<a class="navbar-brand" href="#">대관 서비스</a>
......@@ -54,20 +71,21 @@ function Menu() {
}} className="nav-link">
대관 확인/취소</Link>
</li>
<li className="nav-item">
<Link to={{
pathname: `/acheck/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">
대관 확인/취소(관리자)</Link>
</li>
{user.role === "admin" ? (
<li className="nav-item">
<Link to={{
pathname: `/acheck/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">
대관 확인/취소(관리자)</Link>
</li>) : null}
</ul>
<div className="h-100 mr-3">
<div className="text-white text-right font-weight-light"><small>{name} 안녕하세요</small></div>
<div className="text-white text-right font-weight-light"><small>
<Link to={{
pathname: `/change/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
pathname: `/change/${user._id}`,
state: { id: user._id },
}}>비밀번호 변경</Link> / <span className="logoutBtn" onClick={logout} >로그아웃</span></small></div>
</div>
</div>
......
......@@ -59,7 +59,7 @@ function Check(props) {
<td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>{reserve.approve ? "승인" : "미승인"}</td>
<td>{reserve.check ? (reserve.approve ? "사용가능" : "사용불가") : "승인대기중"}</td>
<td>
<button onClick={() => remove(index)} className="btn btn-danger">
취소
......
......@@ -7,14 +7,13 @@ const router = express.Router();
router.post('/', function (req, res, next) {
console.log('/reserve post req.body', req.body)
const reserve = new Reserve({
user: req.body._id,
date: req.body.date,
starttime: Number(req.body.starttime),
usetime: Number(req.body.usetime),
start: `${req.body.date}T`+`${req.body.starttime}:00:00`,
end: `${req.body.date}T`+`${Number(req.body.starttime)+Number(req.body.usetime)}:00:00`,
start: `${req.body.date}T` + `${req.body.starttime}:00:00`,
end: `${req.body.date}T` + `${Number(req.body.starttime) + Number(req.body.usetime)}:00:00`,
room: req.body.room,
reason: req.body.reason,
students: req.body.students,
......@@ -22,26 +21,60 @@ router.post('/', function (req, res, next) {
num: req.body.students.length + 1,
});
reserve.save()
.then((result) => {
console.log(result);
res.status(201).json(result);
})
.catch((err) => {
console.error(err);
next(err);
});
Reserve.find({ room: req.body.room, approve: true }, function (err, reserves) {
if (err) return res.status(500).json({ error: err });
if (!reserves) {
reserve.save()
.then((result) => {
console.log(result);
res.status(201).json(result);
})
.catch((err) => {
console.error(err);
next(err);
});
}
const strt = new Date(reserve.start)
const endt = new Date(reserve.end)
const reserveArr = reserves.map(item => (
(strt >= new Date(item.start) && strt <= new Date(item.end)) ||
(endt >= new Date(item.start) && endt <= new Date(item.end)) ?
"item" :
null
))
console.log("array", reserveArr)
if (!reserveArr.includes("item")) {
reserve.save()
.then((result) => {
console.log(result);
res.status(201).json(reserves);
})
.catch((err) => {
console.error(err);
next(err);
});
}
else return res.status(404).json({ error: "다른 시간을 선택해주세요." })
})
});
router.get('/room/:room', function (req, res, next) {
console.log('reserves get room req.params', req.params)
Reserve.find({ room: req.params.room, approve: true }, function (err, reserve) {
if (err) return res.status(500).json({ error: err });
console.log('reserve room list', reserve);
res.status(201).json(reserve);
})
})
// router.get('/:_id', verifyToken, function (req, res, next) {
router.get('/:_id', function (req, res, next) {
console.log('/reserves get req.params', req.params)
Reserve.find({ user: req.params._id }, function (err, reserve) {
console.log('id.name',reserve)
if (err) return res.status(500).json({ error: err });
console.log('reserve list', reserve)
res.status(201).json(reserve);
})
});
......@@ -73,9 +106,10 @@ router.delete('/:_id', function (req, res, next) {
router.put('/:id', function (req, res, next) {
console.log('/reserves put req.body', req.params)
Reserve.findOne({ _id: req.params.id }, 'approve', function (err, reserve) {
Reserve.findOne({ _id: req.params.id }, 'check approve', function (err, reserve) {
if (err) return res.status(500).json({ error: err });
reserve.approve = true;
reserve.check = true;
reserve.approve = req.body.approve;
reserve.save()
.then((result) => {
console.log(result);
......
......@@ -5,7 +5,7 @@ module.exports = () => {
if (process.env.NODE_ENV !== 'production') {
mongoose.set('debug', true);
}
mongoose.connect('mongodb://kimpen:kim65811025@localhost:27017/admin', {
mongoose.connect('mongodb://cherry:1q2w3e4r@localhost:27017/admin', {
dbName: 'ku_rental', useNewUrlParser: true, useUnifiedTopology: true,
}, (error) => {
if (error) {
......
......@@ -39,7 +39,10 @@ const reserveSchema = new Schema({
approve: {
type: Boolean,
default: false,
},
check: {
type: Boolean,
default: false,
},
num: {
type: Number,
......
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