Commit 653da10e authored by CHAERIN KIM's avatar CHAERIN KIM
Browse files

스키마, 코드 시간표 맞춰 수정

parent d0f6f520
...@@ -21,6 +21,30 @@ function Apply(props) { ...@@ -21,6 +21,30 @@ function Apply(props) {
}} />; }} />;
} }
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() { function getUser() {
axios.get(`/users/${props.match.params.id}`, { axios.get(`/users/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') }, headers: { authorization: localStorage.getItem('token') },
...@@ -44,7 +68,8 @@ function Apply(props) { ...@@ -44,7 +68,8 @@ function Apply(props) {
initialValues={{ initialValues={{
_id: `${props.match.params.id}`, _id: `${props.match.params.id}`,
date: '', date: '',
time: '', starttime: '',
usetime: '',
room: '', room: '',
reason: '', reason: '',
students: [ students: [
...@@ -56,8 +81,6 @@ function Apply(props) { ...@@ -56,8 +81,6 @@ function Apply(props) {
validationSchema={Yup.object({ validationSchema={Yup.object({
date: Yup.string() date: Yup.string()
.required('날짜를 입력해주세요.'), .required('날짜를 입력해주세요.'),
time: Yup.string()
.required('시간을 입력해주세요.'),
room: Yup.string() room: Yup.string()
.required('강의실 번호를 입력해주세요.'), .required('강의실 번호를 입력해주세요.'),
reason: Yup.string() reason: Yup.string()
...@@ -92,7 +115,6 @@ function Apply(props) { ...@@ -92,7 +115,6 @@ function Apply(props) {
isSubmitting, isSubmitting,
}) => ( }) => (
<div className="row justify-content-center align-items-center"> <div className="row justify-content-center align-items-center">
{console.log(user)}
<form onSubmit={handleSubmit} className="col-sm-3"> <form onSubmit={handleSubmit} className="col-sm-3">
<div className="form-group mb-4"> <div className="form-group mb-4">
<label>대표자</label> <label>대표자</label>
...@@ -102,27 +124,37 @@ function Apply(props) { ...@@ -102,27 +124,37 @@ function Apply(props) {
<label>신청날짜</label> <label>신청날짜</label>
<input <input
className={(touched.date && errors.date ? 'form-control is-invalid' : "form-control")} className={(touched.date && errors.date ? 'form-control is-invalid' : "form-control")}
type="number" type="text"
name="date" name="date"
{...getFieldProps('date')} {...getFieldProps('date')}
placeholder="2020mmdd" placeholder="yyyy-mm-dd"
/> />
{touched.date && errors.date ? ( {touched.date && errors.date ? (
<div className="invalid-feedback text-left">{errors.date}</div> <div className="invalid-feedback text-left">{errors.date}</div>
) : null} ) : null}
</div> </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"> <div className="form-group mb-4">
<label>이용시간</label> <label>이용시간</label>
<input {time(values.starttime)}
className={(touched.time && errors.time ? 'form-control is-invalid' : "form-control")}
type="text"
name="time"
{...getFieldProps('time')}
placeholder="ex) 11:00~14:00"
/>
{touched.time && errors.time ? (
<div className="invalid-feedback text-left">{errors.time}</div>
) : null}
</div> </div>
<div className="form-group mb-4"> <div className="form-group mb-4">
<label>강의실</label> <label>강의실</label>
......
...@@ -7,7 +7,7 @@ function Check(props) { ...@@ -7,7 +7,7 @@ function Check(props) {
useEffect(() => { useEffect(() => {
getReserve(); getReserve();
}, []) }, [])
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') },
...@@ -55,10 +55,10 @@ function Check(props) { ...@@ -55,10 +55,10 @@ function Check(props) {
return ( return (
<tr key={index}> <tr key={index}>
<td>{reserve.date}</td> <td>{reserve.date}</td>
<td>{reserve.time}</td> <td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
<td>{reserve.room}</td> <td>{reserve.room}</td>
<td>{reserve.num}</td> <td>{reserve.num}</td>
<td>{reserve.approve?"사용허가":"글쎄..."}</td> <td>{reserve.approve ? "사용허가" : "글쎄..."}</td>
<td> <td>
<button onClick={() => remove(index)} className="btn btn-danger"> <button onClick={() => remove(index)} className="btn btn-danger">
취소 취소
......
...@@ -8,11 +8,13 @@ router.post('/', function (req, res, next) { ...@@ -8,11 +8,13 @@ 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, 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, room: req.body.room,
name: req.body.name,
reason: req.body.reason, reason: req.body.reason,
students: req.body.students, students: req.body.students,
approve: req.body.approve, approve: req.body.approve,
...@@ -33,7 +35,8 @@ router.post('/', function (req, res, next) { ...@@ -33,7 +35,8 @@ 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) {
console.log('id.name',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);
......
...@@ -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',
...@@ -11,15 +11,20 @@ const reserveSchema = new Schema({ ...@@ -11,15 +11,20 @@ const reserveSchema = new Schema({
date: { date: {
type: String, type: String,
}, },
time: { starttime: {
type: Number,
},
usetime: {
type: Number,
},
start: {
type: String, type: String,
}, },
room: { end: {
type: String, type: String,
}, },
name: { //대표자 이름 room: {
type: String, type: String,
}, },
...@@ -39,8 +44,6 @@ const reserveSchema = new Schema({ ...@@ -39,8 +44,6 @@ const reserveSchema = new Schema({
num: { num: {
type: Number, type: Number,
}, },
}); });
module.exports = mongoose.model('Reserve', reserveSchema); 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