Commit 4e10c469 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

머지하려고 올립니다 신경안쓰셔도 됩니다

parent 813db703
...@@ -7,7 +7,7 @@ const logger = require('morgan'); ...@@ -7,7 +7,7 @@ const logger = require('morgan');
const indexRouter = require('./routes/index'); const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users'); const usersRouter = require('./routes/users');
const loginRouter = require('./routes/login'); const loginRouter = require('./routes/login');
const reserveRouter = require('./routes/reserves'); const reservesRouter = require('./routes/reserves');
const noticeRouter = require('./routes/notices'); const noticeRouter = require('./routes/notices');
const connect = require('./schemas'); const connect = require('./schemas');
...@@ -33,8 +33,9 @@ app.use(express.static(path.join(__dirname, 'public'))); ...@@ -33,8 +33,9 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter); app.use('/', indexRouter);
app.use('/users', usersRouter); app.use('/users', usersRouter);
app.use('/login', loginRouter); app.use('/login', loginRouter);
app.use('/reserves', reserveRouter); app.use('/reserves', reservesRouter);
app.use('/notices', noticeRouter); app.use('/notices', noticeRouter);
app.use('/admin', usersRouter, reservesRouter);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
......
...@@ -51,6 +51,13 @@ function Menu() { ...@@ -51,6 +51,13 @@ function Menu() {
}} className="nav-link"> }} className="nav-link">
대관 확인/취소</Link> 대관 확인/취소</Link>
</li> </li>
<li className="nav-item">
<Link to={{
pathname: `/acheck/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">
대관 확인/취소(관리자)</Link>
</li>
</ul> </ul>
<div> <div>
<div>{name} 안녕하세요.</div> <div>{name} 안녕하세요.</div>
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.css';
function ACheck(props) {
const [reserve, setReserve] = useState([]);
useEffect(() => {
getReserve();
}, [])
function getReserve() {
axios.get(`/admin/`, {
// headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
}
console.log(res.data);
setReserve(res.data);
})
.catch(err => {
alert(err.error)
});
}
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)
});
};
function admit(index) {
axios.put(`/reserves/${reserve[index].approve}`)
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("승인되었습니다!");
getReserve();
})
.catch(err => {
alert(err.error)
});
};
return (
<div>
<Menu />
<div className="">
<table className="table">
<thead>
<tr>
<th>대표자</th>
<th>날짜</th>
<th>시간</th>
<th>강의실</th>
<th>사용인원</th>
<th>승인여부</th>
</tr>
</thead>
<tbody>
{reserve.map((reserve, index) => {
return (
<tr key={index}>
<td>{reserve.user}</td>
<td>{reserve.date}</td>
<td>{reserve.time}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>
<button onClick={() => admit(index)} className="btn btn-primary">
승인
</button>
<button onClick={() => remove(index)} className="btn btn-danger">
거절
</button>
</td>
</tr>
)
})}
</tbody>
</table>
</div>
</div>
)
}
export default ACheck
\ No newline at end of file
...@@ -15,6 +15,7 @@ import Change from './Pages/ChangePage'; ...@@ -15,6 +15,7 @@ import Change from './Pages/ChangePage';
import Apply from './Pages/ApplyPage'; import Apply from './Pages/ApplyPage';
import Check from './Pages/CheckPage'; import Check from './Pages/CheckPage';
import Notice from './Pages/NoticePage'; import Notice from './Pages/NoticePage';
import ACheck from './Pages/ACheckPage';
axios.defaults.validateStatus = function (status) { axios.defaults.validateStatus = function (status) {
return status < 500; // default return status < 500; // default
...@@ -32,6 +33,7 @@ ReactDOM.render( ...@@ -32,6 +33,7 @@ ReactDOM.render(
<Route path="/apply/:id" component={Apply} /> <Route path="/apply/:id" component={Apply} />
<Route path="/check/:id" component={Check} /> <Route path="/check/:id" component={Check} />
<Route path="/notice" component={Notice} /> <Route path="/notice" component={Notice} />
<Route path="/acheck" component={ACheck} />
<Redirect path="/" to="/" /> <Redirect path="/" to="/" />
<Redirect path="/home" to="/" /> <Redirect path="/home" to="/" />
<Redirect path="/change/:id" to="/change"/> <Redirect path="/change/:id" to="/change"/>
......
const express = require('express'); const express = require('express');
const User = require('../schemas/user');
const Reserve = require('../schemas/reserve'); const Reserve = require('../schemas/reserve');
const { verifyToken } = require('./middlewares'); const { verifyToken } = require('./middlewares');
...@@ -8,7 +9,7 @@ router.post('/', function (req, res, next) { ...@@ -8,7 +9,7 @@ router.post('/', function (req, res, next) {
console.log('/reserve post req.body', req.body) console.log('/reserve post req.body', req.body)
const reserve = new Reserve({ const reserve = new Reserve({
id: req.body._id, user: req.body._id,
date: req.body.date, date: req.body.date,
time: req.body.time, time: req.body.time,
room: req.body.room, room: req.body.room,
...@@ -33,14 +34,24 @@ router.post('/', function (req, res, next) { ...@@ -33,14 +34,24 @@ router.post('/', 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', function (req, res, next) {
console.log('/reserves get req.params', req.params) console.log('/reserves get req.params', req.params)
Reserve.find({ id: 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 });
console.log('reserve list',reserve) console.log('reserve list', reserve)
res.status(201).json(reserve); res.status(201).json(reserve);
}) })
}); });
router.get('/admin/:_id', function (req, res, next) {
console.log('/reserves get req.params', req.params)
Reserve.find({ approve: false }).populate('user').exec(function (err, reserve) {
if (err) return res.status(500).json({ error: err });
console.log('reserve list', reserve)
res.status(201).json(reserve);
})
});
router.delete('/:_id', function (req, res, next) { router.delete('/:_id', function (req, res, next) {
console.log('/reserves delete req.params', req.params) console.log('/reserves delete req.params', req.params)
Reserve.findOne({ _id: req.params._id }, function (err, reserve) { Reserve.findOne({ _id: req.params._id }, function (err, reserve) {
...@@ -58,4 +69,21 @@ router.delete('/:_id', function (req, res, next) { ...@@ -58,4 +69,21 @@ router.delete('/:_id', function (req, res, next) {
}) })
}); });
router.put('/:id', function (req, res, next) {
console.log('/reserves put req.body', req.params)
User.findOne({ _id: req.params.id }, 'password', function (err, reserve) {
if (err) return res.status(500).json({ error: err });
reserve.approve = true;
reserve.save()
.then((result) => {
console.log(result);
res.status(201).json(result);
})
.catch((err) => {
console.error(err);
next(err);
});
});
});
module.exports = router; module.exports = router;
...@@ -40,7 +40,7 @@ router.get('/:_id', function (req, res, next) { ...@@ -40,7 +40,7 @@ router.get('/:_id', function (req, res, next) {
if (err) return res.status(500).json({ error: err }); if (err) return res.status(500).json({ error: err });
res.status(201).json(user); res.status(201).json(user);
}) })
}) });
router.put('/change/:id', function (req, res, next) { router.put('/change/:id', function (req, res, next) {
......
...@@ -3,7 +3,7 @@ const mongoose = require('mongoose'); ...@@ -3,7 +3,7 @@ const mongoose = require('mongoose');
const { Schema } = mongoose; const { Schema } = mongoose;
const { Types: { ObjectId } } = Schema; const { Types: { ObjectId } } = Schema;
const reserveSchema = new Schema({ const reserveSchema = new Schema({
id: { user: {
type: ObjectId, type: ObjectId,
required: true, required: true,
ref: 'User', ref: 'User',
......
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