Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-08-08 21:43:10 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0545a25daa9578e9f169095bcbdf92c1099cb28f
0545a25d
1 parent
483d2f26
feat. api user implement
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
70 deletions
server/src/api/index.js
server/src/api/user/index.js
server/src/api/user/user.ctrl.js
server/src/api/index.js
View file @
0545a25
const
Router
=
require
(
'koa-router'
);
const
auth
=
require
(
'./auth'
);
const
bottle
=
require
(
'./bottle'
);
const
hub
=
require
(
'./hub'
);
const
medicine
=
require
(
'./medicine'
);
const
Router
=
require
(
'koa-router'
)
const
auth
=
require
(
'./auth'
)
const
user
=
require
(
'./user'
)
const
bottle
=
require
(
'./bottle'
)
const
hub
=
require
(
'./hub'
)
const
medicine
=
require
(
'./medicine'
)
const
api
=
new
Router
()
;
const
api
=
new
Router
()
api
.
use
(
'/auth'
,
auth
.
routes
());
api
.
use
(
'/bottle'
,
bottle
.
routes
());
api
.
use
(
'/hub'
,
hub
.
routes
());
api
.
use
(
'/medicine'
,
medicine
.
routes
());
api
.
use
(
'/auth'
,
auth
.
routes
())
api
.
user
(
'/user'
,
user
.
routes
())
api
.
use
(
'/bottle'
,
bottle
.
routes
())
api
.
use
(
'/hub'
,
hub
.
routes
())
api
.
use
(
'/medicine'
,
medicine
.
routes
())
module
.
exports
=
api
;
\ No newline at end of file
module
.
exports
=
api
\ No newline at end of file
...
...
server/src/api/user/index.js
View file @
0545a25
const
Router
=
require
(
'koa-router'
)
;
const
userCtrl
=
require
(
'./user.ctrl'
)
;
const
Router
=
require
(
'koa-router'
)
const
userCtrl
=
require
(
'./user.ctrl'
)
const
user
=
new
Router
()
;
const
user
=
new
Router
()
/**
* 현재 유저 정보 조회
...
...
@@ -9,7 +9,7 @@ const user = new Router();
* url : http://localhost:4000/api/user
* return : Object User
*/
user
.
get
(
'/'
,
userCtrl
.
myInfo
)
;
user
.
get
(
'/'
,
userCtrl
.
myInfo
)
/**
* 현재 유저의 타입에 따라 요청 유저 정보 조회(의사 : 환자, 관리자 : 모든 유저)
...
...
@@ -17,7 +17,7 @@ user.get('/', userCtrl.myInfo);
* url : http://localhost:4000/api/user/:reqUserId
* return : status
*/
user
.
get
(
'/:reqUserId'
,
userCtrl
.
getUserDetail
)
;
user
.
get
(
'/:reqUserId'
,
userCtrl
.
getUserDetail
)
/**
* 현재 유저의 타입에 따라 요청 유저 정보 수정(의사 : 환자, 관리자 : 모든 유저)
...
...
@@ -25,5 +25,5 @@ user.get('/', userCtrl.myInfo);
* url : http://localhost:4000/api/user/:reqUserId
* return : status
*/
user
.
patch
(
'/:reqUserId'
,
userCtrl
.
updateReqUser
)
;
user
.
patch
(
'/:reqUserId'
,
userCtrl
.
updateReqUser
)
...
...
server/src/api/user/user.ctrl.js
View file @
0545a25
...
...
@@ -13,10 +13,10 @@ exports.myInfo = async ctx => {
}
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
)
const
user
=
await
User
.
findById
(
userId
)
;
const
user
=
await
User
.
findById
(
userId
)
if
(
!
user
||
!
user
.
userTypeCd
)
{
ctx
.
status
=
403
;
return
;
ctx
.
status
=
403
return
}
let
result
=
{
...
...
@@ -24,108 +24,108 @@ exports.myInfo = async ctx => {
myDoctor
:
null
,
patientList
:
[],
userList
:
[],
}
;
}
if
(
user
.
userTypeCd
===
'NORMAL'
)
{
const
doctor
=
await
User
.
findById
(
user
.
doctorId
)
;
result
.
myDoctor
=
doctor
;
const
doctor
=
await
User
.
findById
(
user
.
doctorId
)
result
.
myDoctor
=
doctor
}
else
if
(
user
.
userTypeCd
===
'DOCTOR'
)
{
const
patientList
=
await
User
.
findAllByDoctorId
(
user
.
userId
)
;
result
.
patientList
=
patientList
;
const
patientList
=
await
User
.
findAllByDoctorId
(
user
.
userId
)
result
.
patientList
=
patientList
}
else
if
(
user
.
userTypeCd
===
'MANAGER'
)
{
const
userList
=
await
User
.
find
()
;
result
.
userList
=
userList
;
const
userList
=
await
User
.
find
()
result
.
userList
=
userList
}
ctx
.
status
=
200
;
ctx
.
body
=
result
;
ctx
.
status
=
200
ctx
.
body
=
result
}
exports
.
getUserDetail
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
const
token
=
ctx
.
req
.
headers
.
authorization
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
ctx
.
status
=
401
return
}
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
)
;
const
user
=
await
User
.
findById
(
userId
)
;
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
)
const
user
=
await
User
.
findById
(
userId
)
if
(
!
user
)
{
ctx
.
status
=
403
;
return
;
ctx
.
status
=
403
return
}
else
if
(
user
.
userTypeCd
===
'NORMAL'
)
{
ctx
.
status
=
403
;
return
;
ctx
.
status
=
403
return
}
let
result
=
{
reqUser
:
user
,
reqUserBottleList
:
[],
}
;
}
if
(
user
.
userTypeCd
===
'DOCTOR'
)
{
const
{
reqUserId
}
=
ctx
.
params
;
const
reqUser
=
await
User
.
findById
(
reqUserId
)
;
const
{
reqUserId
}
=
ctx
.
params
const
reqUser
=
await
User
.
findById
(
reqUserId
)
if
(
!
reqUser
)
{
ctx
.
status
=
404
;
return
;
ctx
.
status
=
404
return
}
if
(
reqUser
.
doctorId
!==
user
.
userId
)
{
ctx
.
status
=
403
;
return
;
ctx
.
status
=
403
return
}
const
reqUserHubList
=
await
Hub
.
findAllByUserId
(
reqUserId
)
;
const
reqUserHubList
=
await
Hub
.
findAllByUserId
(
reqUserId
)
if
(
reqUserHubList
&&
reqUserHubList
.
length
)
{
const
reqUserBottleList
=
[]
;
const
reqUserBottleList
=
[]
await
Promise
.
all
(
reqUserHubList
.
forEach
(
async
hub
=>
{
const
bottle
=
await
Bottle
.
findAllByHubId
(
hub
.
hubId
)
;
reqUserBottleList
.
push
(...
bottle
)
;
}))
;
const
bottle
=
await
Bottle
.
findAllByHubId
(
hub
.
hubId
)
reqUserBottleList
.
push
(...
bottle
)
}))
result
.
reqUserBottleList
=
reqUserBottleList
;
result
.
reqUserBottleList
=
reqUserBottleList
}
}
ctx
.
status
=
200
;
ctx
.
body
=
result
;
ctx
.
status
=
200
ctx
.
body
=
result
}
;
}
exports
.
updateReqUser
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
const
token
=
ctx
.
req
.
headers
.
authorization
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
ctx
.
status
=
401
return
}
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
)
;
const
user
=
await
User
.
findById
(
userId
)
;
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
)
const
user
=
await
User
.
findById
(
userId
)
if
(
!
user
)
{
ctx
.
status
=
403
;
return
;
ctx
.
status
=
403
return
}
if
(
user
.
userTypeCd
===
'MANAGER'
)
{
const
{
useYn
}
=
ctx
.
request
.
body
;
const
{
reqUserId
}
=
ctx
.
params
;
const
{
useYn
}
=
ctx
.
request
.
body
const
{
reqUserId
}
=
ctx
.
params
const
reqUser
=
await
User
.
findById
(
reqUserId
)
;
const
reqUser
=
await
User
.
findById
(
reqUserId
)
if
(
!
reqUser
)
{
ctx
.
status
=
404
;
return
;
ctx
.
status
=
404
return
}
await
reqUser
.
setUseYn
(
useYn
)
;
await
reqUser
.
save
()
;
await
reqUser
.
setUseYn
(
useYn
)
await
reqUser
.
save
()
return
;
return
}
ctx
.
status
=
200
;
ctx
.
status
=
200
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment