Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
reservation-service
Commits
9e22fd14
Commit
9e22fd14
authored
Nov 03, 2020
by
Ha YeaJin
Browse files
행복...하자....
parent
6031e83e
Changes
7
Show whitespace changes
Inline
Side-by-side
server/client/src/Components/Menu.js
View file @
9e22fd14
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
styled
from
'
styled-components
'
;
import
{
Navbar
,
Nav
,
NavDropdown
,
NavLink
}
from
'
react-bootstrap
'
;
import
{
Navbar
,
Nav
,
NavLink
}
from
'
react-bootstrap
'
;
import
axios
from
'
axios
'
;
const
MENU
=
styled
(
Navbar
)
`
background-color: #7B031D;
...
...
@@ -13,6 +14,7 @@ const MENU = styled(Navbar)`
function
Menu
()
{
const
[
state
,
setState
]
=
useState
()
const
[
user
,
setUser
]
=
useState
({
role
:
""
})
const
name
=
localStorage
.
getItem
(
'
name
'
);
function
logout
()
{
...
...
@@ -21,6 +23,21 @@ function Menu() {
setState
(
true
);
}
useEffect
(()
=>
{
acheck
();
},
[])
function
acheck
()
{
axios
.
get
(
`/users/
${
localStorage
.
getItem
(
'
_id
'
)}
`
)
.
then
(
res
=>
{
if
(
res
.
data
.
role
==
"
admin
"
)
{
setUser
(
res
.
data
)
}
}).
catch
(
err
=>
{
alert
(
err
.
error
)
});
}
if
(
state
)
return
<
Redirect
to
=
"
/
"
/>
return
(
<
MENU
expand
=
"
md
"
variant
=
"
dark
"
>
...
...
@@ -42,11 +59,12 @@ function Menu() {
}}
className
=
"
nav-link
"
>
대관
확인
/
취소
<
/NavLink
>
{
user
.
role
===
"
admin
"
?
(
<
NavLink
as
=
{
Link
}
to
=
{{
pathname
:
`/acheck/
${
localStorage
.
getItem
(
'
_id
'
)}
`
,
state
:
{
id
:
localStorage
.
getItem
(
'
_id
'
)
},
}}
className
=
"
nav-link
"
>
대관
확인
/
취소
(
관리자
)
<
/NavLink
>
대관
확인
/
취소
(
관리자
)
<
/NavLink>
)
: null
}
<
/Nav
>
<
Nav
>
<
NavLink
>
...
...
server/client/src/Pages/ACheckPage.js
View file @
9e22fd14
...
...
@@ -30,10 +30,19 @@ function ACheck(props) {
if
(
state
)
return
<
Redirect
to
=
"
/home
"
/>
;
function
remove
(
index
)
{
axios
.
delete
(
`/reserves/
${
reserve
[
index
].
_id
}
`
)
// axios.delete(`/reserves/${reserve[index]._id}`)
// .then(res => {
// if (res.status === 404) return alert(res.data.error)
// alert("삭제되었습니다!");
// getReserve();
// })
// .catch(err => {
// alert(err.error)
// });
axios
.
put
(
`/reserves/
${
reserve
[
index
].
_id
}
`
)
.
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
삭제되었
습니다!
"
);
alert
(
"
승인을 거절했
습니다!
"
);
getReserve
();
})
.
catch
(
err
=>
{
...
...
@@ -42,7 +51,9 @@ function ACheck(props) {
};
function
admit
(
index
)
{
axios
.
put
(
`/reserves/
${
reserve
[
index
].
_id
}
`
)
axios
.
put
(
`/reserves/
${
reserve
[
index
].
_id
}
`
,
{
approve
:
true
,
})
.
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
승인되었습니다!
"
);
...
...
@@ -69,12 +80,13 @@ function ACheck(props) {
<
/tr
>
<
/thead
>
<
tbody
>
{
reserve
.
map
((
reserve
,
index
)
=>
{
{
reserve
!=
""
?
(
reserve
.
map
((
reserve
,
index
)
=>
{
return
(
<
tr
key
=
{
index
}
>
<
td
>
{
reserve
.
user
.
name
}
<
/td
>
<
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
>
...
...
@@ -87,7 +99,7 @@ function ACheck(props) {
<
/td
>
<
/tr
>
)
})
}
}))
:
<
div
>
최근
대관
신청
내역이
없습니다
.
<
/div>
}
<
/tbody
>
<
/table
>
...
...
server/client/src/Pages/ApplyPage.js
View file @
9e22fd14
...
...
@@ -22,7 +22,6 @@ function Apply(props) {
}
function
time
(
starttime
)
{
console
.
log
(
starttime
)
if
(
starttime
==
21
)
{
return
(
<
Field
as
=
"
select
"
name
=
"
usetime
"
>
<
option
value
=
""
>
이용시간을
선택하세요
<
/option
>
...
...
@@ -93,17 +92,21 @@ function Apply(props) {
url
:
'
/reserves
'
,
data
:
values
}).
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
if
(
res
.
status
===
404
)
{
alert
(
res
.
data
.
error
)
return
window
.
location
.
reload
();
}
alert
(
"
신청이 완료되었습니다!
"
);
setState
(
true
);
console
.
log
(
"
res.data
"
,
res
.
data
)
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
//
setTimeout(() => {
//
setSubmitting(false);
//
}, 400); // finish the cycle in handler
setTimeout
(()
=>
{
setSubmitting
(
false
);
},
400
);
// finish the cycle in handler
}}
>
{({
...
...
@@ -208,7 +211,6 @@ function Apply(props) {
>
X
<
/button
>
<
/div
>
<
/div
>
))}
...
...
server/client/src/Pages/CheckPage.js
View file @
9e22fd14
...
...
@@ -59,7 +59,7 @@ function Check(props) {
<
td
>
{
reserve
.
starttime
}
시
~
{(
Number
(
reserve
.
starttime
)
+
reserve
.
usetime
)}
시
<
/td
>
<
td
>
{
reserve
.
room
}
<
/td
>
<
td
>
{
reserve
.
num
}
<
/td
>
<
td
>
{
reserve
.
approve
?
"
승인
"
:
"
미승인
"
}
<
/td
>
<
td
>
{
reserve
.
check
?
(
reserve
.
approve
?
"
사용가능
"
:
"
사용불가
"
)
:
"
승인대기중
"
}
<
/td
>
<
td
>
<
button
onClick
=
{()
=>
remove
(
index
)}
className
=
"
btn btn-danger
"
>
취소
...
...
server/client/src/Pages/SignupPage.js
View file @
9e22fd14
...
...
@@ -4,7 +4,7 @@ import * as Yup from 'yup';
import
axios
from
'
axios
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
styled
from
'
styled-components
'
;
import
{
Col
,
Container
,
Navbar
}
from
'
react-bootstrap
'
;
import
{
Col
,
Container
,
Navbar
,
Button
}
from
'
react-bootstrap
'
;
const
Menu
=
styled
(
Navbar
)
`
background-color: #7B031D;
...
...
@@ -46,7 +46,7 @@ function Signup() {
<
/Menu
>
<
Container
fluid
>
<
Wow
className
=
"
row justify-content-center
"
>
<
Col
md
=
{
4
}
className
=
"
d-flex align-items-center h-10
0
"
>
<
Col
md
=
{
3
}
xs
=
{
11
}
className
=
"
p-
0
"
>
<
Formik
initialValues
=
{{
name
:
''
,
id
:
''
,
password
:
''
,
password2
:
''
,
question
:
''
,
answer
:
''
}}
validationSchema
=
{
Yup
.
object
({
...
...
@@ -154,8 +154,8 @@ function Signup() {
{...
getFieldProps
(
'
answer
'
)}
placeholder
=
"
Input answer
"
/>
<
/div
>
<
b
utton
type
=
"
submit
"
className
=
"
btn btn-
dar
k
"
disabled
=
{
isSubmitting
}
>
회원가입
<
/
b
utton
>
<
b
utton
class
=
"
btn btn-light
"
><
Link
to
=
"
/login
"
>
로그인하러
가기
<
/
Link></
b
utton
>
<
B
utton
type
=
"
submit
"
variant
=
"
secon
dar
y
"
disabled
=
{
isSubmitting
}
>
회원가입
<
/
B
utton
>
<
B
utton
variant
=
"
outline-secondary
"
as
=
{
Link
}
to
=
"
/login
"
>
로그인하러
가기
<
/
B
utton
>
<
/form
>
)}
<
/Formik
>
...
...
server/routes/reserves.js
View file @
9e22fd14
...
...
@@ -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,17 +34,47 @@ 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
);
})
});
...
...
@@ -73,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
);
...
...
server/schemas/reserve.js
View file @
9e22fd14
...
...
@@ -39,7 +39,10 @@ const reserveSchema = new Schema({
approve
:
{
type
:
Boolean
,
default
:
false
,
},
check
:
{
type
:
Boolean
,
default
:
false
,
},
num
:
{
type
:
Number
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment