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
662b4c70
Commit
662b4c70
authored
Oct 11, 2020
by
Choi Ga Young
Browse files
관리자페이지 기능완성
parent
400397ec
Changes
6
Hide whitespace changes
Inline
Side-by-side
server/app.js
View file @
662b4c70
...
@@ -9,6 +9,7 @@ const usersRouter = require('./routes/users');
...
@@ -9,6 +9,7 @@ const usersRouter = require('./routes/users');
const
loginRouter
=
require
(
'
./routes/login
'
);
const
loginRouter
=
require
(
'
./routes/login
'
);
const
reservesRouter
=
require
(
'
./routes/reserves
'
);
const
reservesRouter
=
require
(
'
./routes/reserves
'
);
const
noticeRouter
=
require
(
'
./routes/notices
'
);
const
noticeRouter
=
require
(
'
./routes/notices
'
);
const
connect
=
require
(
'
./schemas
'
);
const
connect
=
require
(
'
./schemas
'
);
const
app
=
express
();
const
app
=
express
();
...
@@ -31,11 +32,11 @@ app.use(cookieParser());
...
@@ -31,11 +32,11 @@ app.use(cookieParser());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)));
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)));
app
.
use
(
'
/
'
,
indexRouter
);
app
.
use
(
'
/
'
,
indexRouter
);
app
.
use
(
'
/users
'
,
usersRouter
);
app
.
use
(
'
/users
'
,
usersRouter
,
reservesRouter
);
app
.
use
(
'
/login
'
,
loginRouter
);
app
.
use
(
'
/login
'
,
loginRouter
);
app
.
use
(
'
/reserves
'
,
reservesRouter
);
app
.
use
(
'
/reserves
'
,
reservesRouter
);
app
.
use
(
'
/notices
'
,
noticeRouter
);
app
.
use
(
'
/notices
'
,
noticeRouter
);
app
.
use
(
'
/admin
'
,
usersRouter
,
reservesRouter
);
// catch 404 and forward to error handler
// catch 404 and forward to error handler
app
.
use
(
function
(
req
,
res
,
next
)
{
app
.
use
(
function
(
req
,
res
,
next
)
{
...
...
server/client/src/Pages/ACheckPage.js
View file @
662b4c70
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
Menu
from
'
../Components/Menu
'
;
import
Menu
from
'
../Components/Menu
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
function
ACheck
(
props
)
{
function
ACheck
(
props
)
{
const
[
state
,
setState
]
=
useState
()
const
[
reserve
,
setReserve
]
=
useState
([]);
const
[
reserve
,
setReserve
]
=
useState
([]);
useEffect
(()
=>
{
useEffect
(()
=>
{
getReserve
();
getReserve
();
},
[])
},
[])
function
getReserve
()
{
function
getReserve
()
{
axios
.
get
(
`/
admin/
`
,
{
axios
.
get
(
`/
users/admin/
${
props
.
match
.
params
.
id
}
`
,
{
//
headers: { authorization: localStorage.getItem('token') },
headers
:
{
authorization
:
localStorage
.
getItem
(
'
token
'
)
},
})
})
.
then
(
res
=>
{
.
then
(
res
=>
{
if
(
res
.
status
!==
201
)
{
if
(
res
.
status
===
404
)
{
alert
(
res
.
data
.
error
);
alert
(
res
.
data
.
error
)
setState
(
true
);
}
}
console
.
log
(
res
.
data
);
console
.
log
(
res
.
data
);
setReserve
(
res
.
data
);
setReserve
(
res
.
data
);
...
@@ -24,6 +27,8 @@ function ACheck(props) {
...
@@ -24,6 +27,8 @@ function ACheck(props) {
alert
(
err
.
error
)
alert
(
err
.
error
)
});
});
}
}
if
(
state
)
return
<
Redirect
to
=
"
/home
"
/>
;
function
remove
(
index
)
{
function
remove
(
index
)
{
axios
.
delete
(
`/reserves/
${
reserve
[
index
].
_id
}
`
)
axios
.
delete
(
`/reserves/
${
reserve
[
index
].
_id
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
...
@@ -37,7 +42,7 @@ function ACheck(props) {
...
@@ -37,7 +42,7 @@ function ACheck(props) {
};
};
function
admit
(
index
)
{
function
admit
(
index
)
{
axios
.
put
(
`/reserves/
${
reserve
[
index
].
approve
}
`
)
axios
.
put
(
`/reserves/
${
reserve
[
index
].
_id
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
승인되었습니다!
"
);
alert
(
"
승인되었습니다!
"
);
...
@@ -67,7 +72,7 @@ function ACheck(props) {
...
@@ -67,7 +72,7 @@ function ACheck(props) {
{
reserve
.
map
((
reserve
,
index
)
=>
{
{
reserve
.
map
((
reserve
,
index
)
=>
{
return
(
return
(
<
tr
key
=
{
index
}
>
<
tr
key
=
{
index
}
>
<
td
>
{
reserve
.
user
}
<
/td
>
<
td
>
{
reserve
.
user
.
name
}
<
/td
>
<
td
>
{
reserve
.
date
}
<
/td
>
<
td
>
{
reserve
.
date
}
<
/td
>
<
td
>
{
reserve
.
time
}
<
/td
>
<
td
>
{
reserve
.
time
}
<
/td
>
<
td
>
{
reserve
.
room
}
<
/td
>
<
td
>
{
reserve
.
room
}
<
/td
>
...
...
server/client/src/Pages/CheckPage.js
View file @
662b4c70
...
@@ -59,7 +59,7 @@ function Check(props) {
...
@@ -59,7 +59,7 @@ function Check(props) {
<
td
>
{
reserve
.
starttime
}
시
~
{(
Number
(
reserve
.
starttime
)
+
reserve
.
usetime
)}
시
<
/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
"
>
취소
취소
...
...
server/client/src/index.js
View file @
662b4c70
...
@@ -33,7 +33,7 @@ ReactDOM.render(
...
@@ -33,7 +33,7 @@ ReactDOM.render(
<
Route
path
=
"
/apply/:id
"
component
=
{
Apply
}
/
>
<
Route
path
=
"
/apply/:id
"
component
=
{
Apply
}
/
>
<
Route
path
=
"
/check/:id
"
component
=
{
Check
}
/
>
<
Route
path
=
"
/check/:id
"
component
=
{
Check
}
/
>
<
Route
path
=
"
/notice
"
component
=
{
Notice
}
/
>
<
Route
path
=
"
/notice
"
component
=
{
Notice
}
/
>
<
Route
path
=
"
/acheck
"
component
=
{
ACheck
}
/
>
<
Route
path
=
"
/acheck
/:id
"
component
=
{
ACheck
}
/
>
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/home
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/home
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/change/:id
"
to
=
"
/change
"
/>
<
Redirect
path
=
"
/change/:id
"
to
=
"
/change
"
/>
...
...
server/routes/reserves.js
View file @
662b4c70
...
@@ -46,8 +46,7 @@ router.get('/:_id', function (req, res, next) {
...
@@ -46,8 +46,7 @@ router.get('/:_id', function (req, res, next) {
});
});
router
.
get
(
'
/admin/:_id
'
,
function
(
req
,
res
,
next
)
{
router
.
get
(
'
/admin/:_id
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/reserves get req.params
'
,
req
.
params
)
console
.
log
(
'
/reserves/admin get req.params
'
,
req
.
params
)
Reserve
.
find
({
approve
:
false
}).
populate
(
'
user
'
).
exec
(
function
(
err
,
reserve
)
{
Reserve
.
find
({
approve
:
false
}).
populate
(
'
user
'
).
exec
(
function
(
err
,
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
)
...
@@ -74,7 +73,7 @@ router.delete('/:_id', function (req, res, next) {
...
@@ -74,7 +73,7 @@ router.delete('/:_id', function (req, res, next) {
router
.
put
(
'
/:id
'
,
function
(
req
,
res
,
next
)
{
router
.
put
(
'
/:id
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/reserves put req.body
'
,
req
.
params
)
console
.
log
(
'
/reserves put req.body
'
,
req
.
params
)
U
ser
.
findOne
({
_id
:
req
.
params
.
id
},
'
password
'
,
function
(
err
,
reserve
)
{
Re
ser
ve
.
findOne
({
_id
:
req
.
params
.
id
},
'
approve
'
,
function
(
err
,
reserve
)
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
reserve
.
approve
=
true
;
reserve
.
approve
=
true
;
reserve
.
save
()
reserve
.
save
()
...
...
server/routes/users.js
View file @
662b4c70
...
@@ -42,6 +42,16 @@ router.get('/:_id', function (req, res, next) {
...
@@ -42,6 +42,16 @@ router.get('/:_id', function (req, res, next) {
})
})
});
});
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
)
{
router
.
put
(
'
/change/:id
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/change put req.body
'
,
req
.
params
)
console
.
log
(
'
/change put req.body
'
,
req
.
params
)
...
...
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