Commit e1bf1bfd authored by Kim, Subin's avatar Kim, Subin
Browse files

server 병합

parent db9696fc
......@@ -12,6 +12,7 @@ const loginRouter = require('./routes/login');
const reservesRouter = require('./routes/reserves');
const noticeRouter = require('./routes/notices');
const connect = require('./schemas');
const writesRouter = require('./routes/writes');
const app = express();
connect();
......@@ -31,6 +32,7 @@ app.use('/users', usersRouter, reservesRouter);
app.use('/login', loginRouter);
app.use('/reserves', reservesRouter);
app.use('/notices', noticeRouter);
app.use('/writes', writesRouter);
app.listen(port, () => console.log(port));
......
......@@ -4,9 +4,12 @@ import "tui-calendar/dist/tui-calendar.css";
import "tui-date-picker/dist/tui-date-picker.css";
import "tui-time-picker/dist/tui-time-picker.css";
import moment from 'moment';
import axios from 'axios';
function Cal(props) {
const calendarRef = useRef(null);
const [reserve, setReserve] = useState([]);
const [period, setPeriod] = useState();
const [myTheme, setMyTheme] = useState({
'common.dayname.color': '#333',
'common.today.color': '#333',
......@@ -15,6 +18,26 @@ function Cal(props) {
// Theme object to extends default dark theme.
});
function getReserve(room) {
axios.get(`/reserves/room/${room}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
const reserves = res.data.map(item => ({
id: item._id,
start: item.start,
end: item.end,
calendarId: 'Subject',
category: 'time',
}))
console.log("room list", res.data);
setReserve(reserves);
})
.catch(err => {
alert(err.error)
});
}
function getDataAction(target) {
return target.dataset ? target.dataset.action : target.getAttribute('data-action');
}
......@@ -42,23 +65,23 @@ function Cal(props) {
function setRenderRangeText() {
const cal = calendarRef.current.getInstance();
const renderRange = document.getElementById('renderRange');
// const renderRange = document.getElementById('renderRange');
let html = [];
html.push(moment(cal.getDateRangeStart().getTime()).format('YYYY.MM.DD'));
html.push(' ~ ');
html.push(moment(cal.getDateRangeEnd().getTime()).format(' MM.DD'));
renderRange.innerHTML = html.join('');
console.log(html)
setPeriod(html.join(''))
// cal.render();
}
useEffect(() => {
setRenderRangeText()
setRenderRangeText();
getReserve(props.room);
}, [])
return (
<div>
<div id="menu" >
<div id="menu">
<span id="menu-navi" onClick={(e) => onClickNavi(e)}>
<button type="button" className="btn btn-default btn-sm move-today" data-action="move-today">Today</button>
<button type="button" className="btn btn-default btn-sm move-day" data-action="move-prev">
......@@ -68,9 +91,8 @@ function Cal(props) {
<i className="calendar-icon ic-arrow-line-right" data-action="move-next"></i>
</button>
</span>
<span id="renderRange" className="render-range"></span>
<span id="renderRange" className="render-range" style={{ height: "5em" }}>{period}</span>
</div>
<Calendar
ref={calendarRef}
height="100%"
......@@ -91,7 +113,7 @@ function Cal(props) {
// return display: "none"
// }
// }
schedules={props.schedules}
schedules={reserve}
scheduleView={['time']}
taskView={false}
theme={myTheme}
......
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import Schedule from '../Components/Schedule';
import styled from 'styled-components';
// import styled from 'styled-components';
import Tabs from 'react-bootstrap/Tabs';
import Tab from 'react-bootstrap/Tab';
......@@ -12,55 +12,6 @@ import Tab from 'react-bootstrap/Tab';
// `
function Home() {
const [sched1, setSched1] = useState();
const [sched2, setSched2] = useState();
const [sched3, setSched3] = useState();
useEffect(() => {
const dd = [{
id: '1',
calendarId: 'Subject',
category: 'time',
start: '2020-11-02T11:00:00',
end: '2020-11-02T12:00:00',
}, {
id: '2',
calendarId: 'Subject',
category: 'time',
start: '2020-11-03T10:00:00',
end: '2020-11-03T11:00:00',
}];
setSched1(dd)
const dd2 = [{
id: '3',
calendarId: 'Subject',
category: 'time',
start: '2020-11-03T12:00:00',
end: '2020-11-03T13:00:00',
}, {
id: '4',
calendarId: 'Subject',
category: 'time',
start: '2020-11-04T10:00:00',
end: '2020-11-04T11:00:00',
}];
setSched2(dd2)
const dd3 = [{
id: '5',
calendarId: 'Subject',
category: 'time',
start: '2020-11-04T12:00:00',
end: '2020-11-04T13:00:00',
}, {
id: '6',
calendarId: 'Subject',
category: 'time',
start: '2020-11-05T10:00:00',
end: '2020-11-05T11:00:00',
}];
setSched3(dd3)
}, []);
return (
<div>
<Menu />
......@@ -75,24 +26,35 @@ function Home() {
</p>
<Tabs defaultActiveKey="9-116" id="uncontrolled-tab-example">
<Tab eventKey="9-116" title="9-116">
<Schedule schedules={sched1} />
<Schedule room={"9-116"} />
</Tab>
<Tab eventKey="7-234" title="7-234">
<Schedule schedules={sched2} />
<Schedule room={"7-234"} />
</Tab>
<Tab eventKey="25-101" title="25-101">
<Schedule schedules={sched3} />
<Schedule room={"25-101"} />
</Tab>
</Tabs>
{/* <Tab className="nav nav-tabs nav-justified mt-4" id="myTab" role="tablist" style={show ? {} : { display: "none" }}>
{/* <Tab className="nav nav-tabs nav-justified mt-4" id="myTab" role="tablist" >
<li className="nav-item">
<a className="nav-link active" id="7-tab" data-toggle="tab" href="#tab-7" role="tab" aria-controls="7" aria-selected="true"> 7-223 </a>
</li>
<li className="nav-item">
<a className="nav-link" id="9-tab" data-toggle="tab" href="#tab-9" role="tab" aria-controls="9" aria-selected="false"> 9-116 </a>
</li>
<li className="nav-item">
<a className="nav-link" id="25-tab" data-toggle="tab" href="#tab-25" role="tab" aria-controls="25" aria-selected="false"> 25-101 </a>
</li>
</Tab>
<div className="tab-content row justify-content-center" id="myTabContent" style={show ? {} : { display: "none" }}>
<div className="tab-content row justify-content-center" id="myTabContent" >
<div className="tab-pane fade show active col-md-11 col-12" id="tab-7" role="tabpanel" aria-labelledby="7-tab">
<Schedule day={sendDate} schedules={sched1}/>
{console.log(sched1)}
<Schedule schedules={sched1}/>
</div>
<div className="tab-pane fade show col-md-11 col-12" id="tab-9" role="tabpanel" aria-labelledby="9-tab">
<Schedule schedules={sched2}/>
</div>
<div className="tab-pane fade show col-md-11 col-12" id="tab-25" role="tabpanel" aria-labelledby="25-tab">
<Schedule schedules={sched3}/>
</div>
</div> */}
<h3>유의사항</h3>
......
......@@ -6,12 +6,15 @@ const router = express.Router();
router.get('/', function (req, res, next) {
Notice.find({}).sort({ post_date: -1 })
.then((notices) => {
res.json(notices);
res.status(201).json(notices);
})
.catch((err) => {
console.error(err);
next(err);
});
// res.status(404).json({error:"없음."})
res.status(201).json(notices);
});
module.exports = router;
\ No newline at end of file
......@@ -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,6 +21,10 @@ router.post('/', function (req, res, next) {
num: req.body.students.length + 1,
});
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);
......@@ -31,15 +34,46 @@ router.post('/', function (req, res, next) {
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);
})
});
......@@ -72,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);
......
const express = require('express');
// const path = require('path');
// const multer = require('multer');
// const fs = require('fs');
const Notice = require('../schemas/notice');
const router = express.Router();
router.post('/', function (req, res, next) {
console.log("writes req.body", req.body)
const notice = new Notice({
notice_title: req.body.title,
notice_author: "예진",
notice_content: req.body.content
});
console.log(notice);
notice.save()
.then((result) => {
console.log(result);
res.status(201).json(result);
})
.catch((err) => {
console.error(err);
next(err);
});
});
module.exports = router;
\ No newline at end of file
......@@ -22,20 +22,28 @@ const reserveSchema = new Schema({
},
end: {
type: String,
},
room: {
type: String,
},
reason: {
type: String,
},
students: {
type: Array,
},
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