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

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

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