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-05-22 00:06:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4e14abbfc33ae7c46bc479f53844ca71bd8d0a12
4e14abbf
1 parent
7e6264b9
feat. get all of bottle list -> get bottle list of hub
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
18 deletions
server/src/api/bottle/bottle.ctrl.js
server/src/api/bottle/index.js
server/src/api/bottle/bottle.ctrl.js
View file @
4e14abb
...
...
@@ -4,6 +4,7 @@ const Hub = require('../../models/hub');
const
Medicine
=
require
(
'../../models/medicine'
);
const
Mqtt
=
require
(
'../../lib/MqttModule'
);
const
jwt
=
require
(
'jsonwebtoken'
);
const
{
createIndexes
}
=
require
(
'../../models/bottle'
);
//약병 등록
exports
.
bottleConnect
=
async
(
ctx
)
=>
{
...
...
@@ -171,13 +172,20 @@ exports.getBottleList = async(ctx) => {
}
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
hubList
=
await
Hub
.
find
({
userId
})
if
(
!
hubList
||
!
hubList
.
length
)
{
const
{
hubId
}
=
ctx
.
params
;
const
hub
=
await
Hub
.
findByHubId
(
hubId
);
if
(
!
hub
)
{
ctx
.
status
=
404
;
return
;
}
const
bottleList
=
await
getBottleListByHub
(
hubList
);
if
(
hub
.
getHub_UserId
()
!==
userId
)
{
ctx
.
status
=
403
;
return
;
}
const
bottleList
=
await
Bottle
.
find
({
hubId
});
if
(
!
bottleList
||
!
bottleList
.
length
)
{
ctx
.
status
=
404
;
return
;
...
...
@@ -185,17 +193,5 @@ exports.getBottleList = async(ctx) => {
ctx
.
status
=
200
;
ctx
.
body
=
bottleList
;
}
const
getBottleListByHub
=
async
(
hubList
)
=>
{
const
result
=
[]
for
(
const
hub
of
hubList
)
{
const
bottle
=
await
Bottle
.
find
({
hubId
:
hub
.
hubId
});
result
.
push
(...
bottle
)
}
return
result
;
}
\ No newline at end of file
...
...
server/src/api/bottle/index.js
View file @
4e14abb
...
...
@@ -36,11 +36,11 @@ bottle.get('/:bottleId', bottleCtrl.lookupInfo);
bottle
.
patch
(
'/:bottleId'
,
bottleCtrl
.
setMedicine
);
/**
* 현재 로그인한 유저의 약병 리스트를 가져옴
* 현재 로그인한 유저의
허브 중, 해당 허브에 등록된
약병 리스트를 가져옴
* request parameter : x
* url : http://localhost:4000/api/bottle
* url : http://localhost:4000/api/bottle
/hub/:hubId
* return : bottle List(json type List)
*/
bottle
.
get
(
'/'
,
bottleCtrl
.
getBottleList
)
bottle
.
get
(
'/
hub/:hubId
'
,
bottleCtrl
.
getBottleList
)
module
.
exports
=
bottle
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment