Commit 98431c1e authored by Ha YeaJin's avatar Ha YeaJin
Browse files

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

parents e991eb08 662b4c70
......@@ -7,8 +7,9 @@ const logger = require('morgan');
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const loginRouter = require('./routes/login');
const reserveRouter = require('./routes/reserves');
const reservesRouter = require('./routes/reserves');
const noticeRouter = require('./routes/notices');
const connect = require('./schemas');
const app = express();
......@@ -31,11 +32,12 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/users', usersRouter, reservesRouter);
app.use('/login', loginRouter);
app.use('/reserves', reserveRouter);
app.use('/reserves', reservesRouter);
app.use('/notices', noticeRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
......
import React, { useState, useEffect } from 'react';
import { Field, Formik } from 'formik';
import axios from 'axios';
import { render } from 'react-dom';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
function List(props) {
function remove() {
console.log(props._id)
axios.delete(`/reserves/${props._id}`, { data: { _id: props._id, }})
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("신청이 완료되었습니다!")
})
.catch(err => {
alert(err.error)
});
};
return (
<div>
<div>날짜 : {props.date}</div>
<div>이름 : {props.name}</div>
<div>강의실 : {props.room}</div>
<div>시간 : {props.time}</div>
<div>사용인원 : {props.num}</div>
<div>{props._id}</div>
<form onSubmit={remove} className="col-sm-3">
<button type="submit" className="btn btn-dark">
신청 취소
</button>
</form>
</div>
)
}
export default List;
\ No newline at end of file
......@@ -39,11 +39,13 @@ function Menu() {
<Link to="/notice" className="nav-link">공지사항</Link>
</li>
<li className="nav-item">
{console.log(name)}
<Link to="/home" className="nav-link">대관 현황</Link>
</li>
<li className="nav-item">
<Link to="/apply" className="nav-link">대관 신청</Link>
<Link to={{
pathname: `/apply/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">대관 신청</Link>
</li>
<li className="nav-item">
<Link to={{
......@@ -52,6 +54,13 @@ 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>
</ul>
<div className="h-100 mr-3">
<div className="text-white text-right font-weight-light"><small>{name} 안녕하세요</small></div>
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import axios from 'axios';
import { Link, Redirect } from 'react-router-dom';
import 'bootstrap/dist/css/bootstrap.css';
function ACheck(props) {
const [state, setState] = useState()
const [reserve, setReserve] = useState([]);
useEffect(() => {
getReserve();
}, [])
function getReserve() {
axios.get(`/users/admin/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status === 404) {
alert(res.data.error)
setState(true);
}
console.log(res.data);
setReserve(res.data);
})
.catch(err => {
alert(err.error)
});
}
if (state) return <Redirect to="/home" />;
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]._id}`)
.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.name}</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
import React, { useState, useEffect } from 'react';
import { Formik } from 'formik';
import { Formik, Field, ErrorMessage, FieldArray } from 'formik';
import Menu from '../Components/Menu';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.css';
import * as Yup from 'yup';
import { Redirect } from 'react-router-dom';
function Apply(props) {
const [state, setState] = useState();
const [user, setUser] = useState({ name: "" });
useEffect(() => {
getUser();
}, [])
if (state) {
return <Redirect to={{
pathname: `/check/${props.match.params.id}`,
state: { id: props.match.params.id },
}} />;
}
function time(starttime) {
console.log(starttime)
if (starttime == 21) {
return (<Field as="select" name="usetime">
<option value="">이용시간을 선택하세요</option>
<option value="1">1시간</option>
</Field>)
}
if (starttime == 20) {
return (<Field as="select" name="usetime">
<option value="">이용시간을 선택하세요</option>
<option value="1">1시간</option>
<option value="2">2시간</option>
</Field>)
}
return (<Field as="select" name="usetime">
<option value="">이용시간을 선택하세요</option>
<option value="1">1시간</option>
<option value="2">2시간</option>
<option value="3">3시간</option>
</Field>)
}
function getUser() {
axios.get(`/users/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
}
console.log(res.data);
setUser(res.data);
})
.catch(err => {
alert(err.error)
});
}
function Apply() {
return (
<div>
<Menu />
<div className="container">apply
<Formik
initialValues={{
date: "20201003",
time: "시간",
room: "9-116",
name: "종윤",
_id: "5f6fa20001988e5604603870",
reason: "study hard",
member: "jinju rkyoung",
approve: false,
num: 5,
_id: `${props.match.params.id}`,
date: '',
starttime: '',
usetime: '',
room: '',
reason: '',
students: [
{
member: '',
},
],
}}
validationSchema={Yup.object({
date: Yup.string()
.required('날짜를 입력해주세요.'),
room: Yup.string()
.required('강의실 번호를 입력해주세요.'),
reason: Yup.string()
.required('대관목적을 입력해주세요.'),
})}
onSubmit={(values, { setSubmitting }) => {
console.log(values)
axios({
method: 'post',
url: '/reserves',
data: values,
data: values
}).then(res => {
if (res.status === 404) return alert(res.data.error)
alert("신청이 완료되었습니다!")
alert("신청이 완료되었습니다!");
setState(true);
})
.catch(err => {
alert(err.error)
});
setTimeout(() => {
setSubmitting(false);
}, 400); // finish the cycle in handler
// setTimeout(() => {
// setSubmitting(false);
// }, 400); // finish the cycle in handler
}}
>
{({
errors,
touched,
values,
handleSubmit,
getFieldProps,
isSubmitting,
}) => (
<div className="row justify-content-center align-items-center">
<form onSubmit={handleSubmit} className="col-sm-3">
<div className="form-group mb-4">
<label>대표자</label>
<div>{user.name}</div>
</div>
<div className="form-group mb-4">
<label>신청날짜</label>
<input
className={(touched.date && errors.date ? 'form-control is-invalid' : "form-control")}
type="text"
name="date"
{...getFieldProps('date')}
placeholder="yyyy-mm-dd"
/>
{touched.date && errors.date ? (
<div className="invalid-feedback text-left">{errors.date}</div>
) : null}
</div>
<div className="form-group mb-4">
<label>이용시작시간</label>
<Field as="select" name="starttime">
<option value="">이용시작시간</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
</Field>
</div>
<div className="form-group mb-4">
<label>이용시간</label>
{time(values.starttime)}
</div>
<div className="form-group mb-4">
<label>강의실</label>
<input
className={(touched.room && errors.room ? 'form-control is-invalid' : "form-control")}
type="text"
name="room"
{...getFieldProps('room')}
placeholder="bn-nnn"
/>
{touched.room && errors.room ? (
<div className="invalid-feedback text-left">{errors.room}</div>
) : null}
</div>
<div className="form-group mb-4">
<label>대관목적</label>
<input
className={(touched.reason && errors.reason ? 'form-control is-invalid' : "form-control")}
type="text"
name="reason"
{...getFieldProps('reason')}
placeholder="대관목적을 입력해 주세요."
/>
{touched.reason && errors.reason ? (
<div className="invalid-feedback text-left">{errors.reason}</div>
) : null}
</div>
<div className="form-group mb-4">
<FieldArray name="students">
{({ insert, remove, push }) => (
<div>
<label>이용자</label>
{
values.students.map((student, index) => (
<div className="row" key={index}>
<div className="col">
<Field
name={`students.${index}.member`}
placeholder="이용자 성함을 입력하세요."
type="text"
/>
<ErrorMessage
name={`friends.${index}.name`}
component="div"
className="field-error"
/>
<button
type="button"
className="secondary"
onClick={() => remove(index)}
>
X
</button>
</div>
</div>
))}
<button
type="button"
className="btn btn-primary"
onClick={() => push({ member: '' })}
>
추가
</button>
</div>
)}
</FieldArray>
</div>
<button type="submit" className="btn btn-dark" disabled={isSubmitting}>
Sign Up
신청하기
</button>
</form>
</div>
)}
</Formik>
</div>
</div>
)
}
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import List from '../Components/List';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.css';
function Check(props) {
const [reserve, setReserve] = useState([]);
useEffect(() => {
getReserve();
}, [])
function getReserve() {
axios.get(`/reserves/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
......@@ -19,18 +24,53 @@ function Check(props) {
alert(err.error)
});
}
const [reserve, setReserve] = useState([]);
useEffect(() => {
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)
});
};
return (
<div>
<Menu />
<div className="container">check
{reserve.map((reserve, index) =>
<List id={props.match.params.id} index={index} date={reserve.date} name={reserve.name} room={reserve.room} time={reserve.time} num={reserve.num} _id={reserve._id}/>
)}
<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.date}</td>
<td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>{reserve.approve ? "승인" : "미승인"}</td>
<td>
<button onClick={() => remove(index)} className="btn btn-danger">
취소
</button>
</td>
</tr>
)
})}
</tbody>
</table>
</div>
</div>
)
......
......@@ -15,6 +15,7 @@ import Change from './Pages/ChangePage';
import Apply from './Pages/ApplyPage';
import Check from './Pages/CheckPage';
import Notice from './Pages/NoticePage';
import ACheck from './Pages/ACheckPage';
axios.defaults.validateStatus = function (status) {
return status < 500; // default
......@@ -29,9 +30,10 @@ ReactDOM.render(
<Route path="/signup" component={Signup} />
<Route path="/find" component={Find} />
<Route path="/change" component={Change} />
<Route path="/apply" component={Apply} />
<Route path="/apply/:id" component={Apply} />
<Route path="/check/:id" component={Check} />
<Route path="/notice" component={Notice} />
<Route path="/acheck/:id" component={ACheck} />
<Redirect path="/" to="/" />
<Redirect path="/home" to="/" />
<Redirect path="/change/:id" to="/change"/>
......
const express = require('express');
const User = require('../schemas/user');
const Reserve = require('../schemas/reserve');
const { verifyToken } = require('./middlewares');
......@@ -8,15 +9,17 @@ 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,
time: req.body.time,
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`,
room: req.body.room,
name: req.body.name,
id: req.body._id,
reason: req.body.reason,
member: req.body.member,
students: req.body.students,
approve: req.body.approve,
num: req.body.num,
num: req.body.students.length + 1,
});
reserve.save()
......@@ -33,14 +36,24 @@ router.post('/', function (req, res, next) {
// 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({ id: req.params._id }, function (err, reserve) {
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)
console.log('reserve list', reserve)
res.status(201).json(reserve);
})
});
router.get('/admin/:_id', 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 });
console.log('reserve list', reserve)
res.status(201).json(reserve);
})
});
router.delete('/:_id', function (req, res, next) {
console.log('/reserves delete req.params', req.params)
Reserve.findOne({ _id: req.params._id }, function (err, reserve) {
......@@ -58,4 +71,21 @@ 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) {
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;
......@@ -34,6 +34,25 @@ router.post('/', function (req, res, next) {
})
});
router.get('/:_id', 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 });
res.status(201).json(user);
})
});
router.get('/admin/:_id', function (req, res, next) {
console.log('/admin get req.params', req.params)
User.findOne({ _id: req.params._id }, 'role', function (err, user) {
if (err) return res.status(500).json({ error: err });
if (user.role == 'admin') {
next();
}
else return res.status(404).json({ error: '권한이 없습니다.' })
})
});
router.put('/change/:id', function (req, res, next) {
console.log('/change put req.body', req.params)
User.findOne({ _id: req.params.id }, 'password', function (err, user) {
......
......@@ -5,7 +5,7 @@ module.exports = () => {
if (process.env.NODE_ENV !== 'production') {
mongoose.set('debug', true);
}
mongoose.connect('mongodb://hyj:hyj3657@localhost:27017/admin', {
mongoose.connect('mongodb://rkyoung7:rkdud127@localhost:27017/admin', {
dbName: 'ku_rental', useNewUrlParser: true, useUnifiedTopology: true,
}, (error) => {
if (error) {
......
......@@ -3,7 +3,7 @@ const mongoose = require('mongoose');
const { Schema } = mongoose;
const { Types: { ObjectId } } = Schema;
const reserveSchema = new Schema({
id: {
user: {
type: ObjectId,
required: true,
ref: 'User',
......@@ -11,15 +11,20 @@ const reserveSchema = new Schema({
date: {
type: String,
},
time: {
starttime: {
type: Number,
},
usetime: {
type: Number,
},
start: {
type: String,
},
room: {
end: {
type: String,
},
name: { //대표자 이름
room: {
type: String,
},
......@@ -27,8 +32,8 @@ const reserveSchema = new Schema({
type: String,
},
member: {
type: String,
students: {
type: Array,
},
approve: {
......@@ -39,8 +44,6 @@ const reserveSchema = new Schema({
num: {
type: Number,
},
});
module.exports = mongoose.model('Reserve', reserveSchema);
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