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-10-12 16:53:42 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
e4e0fa296c53820359657589a91f7375dc1e1325
e4e0fa29
2 parents
a6265eb9
44b31e31
Merge branch 'server' into web
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
25 deletions
server/src/api/auth/auth.ctrl.js
server/src/api/bottle/bottle.ctrl.js
server/src/api/bottle/index.js
server/src/api/hub/hub.ctrl.js
server/src/api/hub/index.js
server/src/models/bottle.js
server/src/models/hub.js
server/src/api/auth/auth.ctrl.js
View file @
e4e0fa2
...
...
@@ -4,7 +4,6 @@ const Profile = require('../../models/profile');
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
Hub
=
require
(
'../../models/hub'
);
const
Bottle
=
require
(
'../../models/bottle'
);
const
BottleMedicine
=
require
(
'../../models/bottleMedicine'
);
const
PatientInfo
=
require
(
'../../models/patientInfo'
);
const
{
uploadDoctorLicense
}
=
require
(
'../../util/GoogleCloudStorage'
);
const
Joi
=
require
(
'joi'
);
...
...
server/src/api/bottle/bottle.ctrl.js
View file @
e4e0fa2
...
...
@@ -27,7 +27,7 @@ exports.bottleConnect = async(ctx) => {
return
;
}
const
{
bottleId
,
hubId
}
=
ctx
.
request
.
body
;
const
{
bottleId
,
hubId
,
bottleNm
}
=
ctx
.
request
.
body
;
const
isExistBottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
if
(
isExistBottle
)
{
...
...
@@ -54,7 +54,8 @@ exports.bottleConnect = async(ctx) => {
const
newBottle
=
new
Bottle
({
bottleId
,
hubId
hubId
,
bottleNm
,
});
const
client
=
await
Mqtt
.
mqttOn
(
hosting
);
...
...
@@ -363,6 +364,50 @@ exports.setMedicineWeight = async ctx => {
};
//약병 이름 변경
exports
.
setBottleName
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
ctx
.
status
=
403
;
return
;
}
const
{
bottleId
}
=
ctx
.
params
;
const
{
bottleNm
}
=
ctx
.
request
.
body
;
const
bottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
if
(
!
bottle
)
{
ctx
.
status
=
404
;
ctx
.
body
=
{
error
:
'약병 찾을 수 없음.'
,
}
return
;
}
const
hub
=
await
Hub
.
findByHubId
(
bottle
.
getHubId
());
if
(
hub
.
getHub_UserId
()
!==
userId
)
{
ctx
.
status
=
403
;
ctx
.
body
=
{
error
:
'해당 허브 권한 없음'
,
}
return
;
}
await
bottle
.
setBottleNm
(
bottleNm
);
await
bottle
.
save
();
ctx
.
status
=
200
;
};
// //비어있는 약병에 의사를 등록한다.
// exports.registerDoctorToBottle = async ctx => {
// const token = ctx.req.headers.authorization;
...
...
server/src/api/bottle/index.js
View file @
e4e0fa2
...
...
@@ -52,6 +52,14 @@ bottle.patch('/:bottleId', bottleCtrl.setMedicine);
bottle
.
patch
(
'/weight/:bottleId'
,
bottleCtrl
.
setMedicineWeight
);
/**
* 약병 이름 변경
* request parameter : bottleid, bottleNm
* url : http://localhost:4000/api/bottle/name/:bottleId
* return : null
*/
bottle
.
patch
(
'/name/:bottleId'
,
bottleCtrl
.
setBottleName
);
/**
* 비어있는 약병에 전담의 등록
* request parameter : bottleId, doctorId
* url : http://localhost:4000/api/bottle/doctor/:bottleId
...
...
server/src/api/hub/hub.ctrl.js
View file @
e4e0fa2
...
...
@@ -6,6 +6,7 @@ const Mqtt = require('../../util/MqttModule');
const
DataProcess
=
require
(
'../../util/DataProcess'
);
const
jwt
=
require
(
'jsonwebtoken'
);
//허브 연결
exports
.
hubConnect
=
async
(
ctx
)
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
...
...
@@ -21,7 +22,7 @@ exports.hubConnect = async (ctx) => {
return
;
}
const
{
hubId
,
host
}
=
ctx
.
request
.
body
;
const
{
hubId
,
host
,
hubNm
,
}
=
ctx
.
request
.
body
;
const
isExistHub
=
await
Hub
.
findByHubId
(
hubId
);
if
(
isExistHub
)
{
...
...
@@ -39,7 +40,8 @@ exports.hubConnect = async (ctx) => {
const
hub
=
new
Hub
({
hubId
,
hosting
,
userId
userId
,
hubNm
,
});
await
hub
.
save
();
...
...
@@ -48,6 +50,44 @@ exports.hubConnect = async (ctx) => {
};
//허브 연결 해제
exports
.
hubDisconnect
=
async
(
ctx
)
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
ctx
.
status
=
403
;
return
;
}
const
{
hubId
}
=
ctx
.
params
;
const
hub
=
await
Hub
.
findByHubId
(
hubId
);
if
(
!
hub
)
{
ctx
.
status
=
404
;
return
;
}
if
(
hub
.
getHub_UserId
()
!==
userId
)
{
ctx
.
status
=
403
;
return
;
}
const
hosting
=
await
hub
.
getHubHost
();
Mqtt
.
mqttOff
(
hosting
);
await
Bottle
.
deleteMany
({
hubId
});
await
Hub
.
deleteOne
({
hubId
});
ctx
.
status
=
204
;
};
//허브 정보 조회
exports
.
getHubList
=
async
(
ctx
)
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
...
...
@@ -75,7 +115,8 @@ exports.getHubList = async(ctx) => {
};
};
exports
.
hubDisconnect
=
async
(
ctx
)
=>
{
//허브 이름 변경
exports
.
setHubName
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
...
...
@@ -91,22 +132,9 @@ exports.hubDisconnect = async(ctx) => {
}
const
{
hubId
}
=
ctx
.
params
;
const
{
hubNm
}
=
ctx
.
request
.
body
;
const
hub
=
await
Hub
.
findByHubId
(
hubId
);
if
(
!
hub
)
{
ctx
.
status
=
404
;
return
;
}
if
(
hub
.
getHub_UserId
()
!==
userId
)
{
ctx
.
status
=
403
;
return
;
}
await
Hub
.
updateOne
({
hubId
},
{
hubNm
});
const
hosting
=
await
hub
.
getHubHost
();
Mqtt
.
mqttOff
(
hosting
);
await
Bottle
.
deleteMany
({
hubId
});
await
Hub
.
deleteOne
({
hubId
});
ctx
.
status
=
204
;
ctx
.
status
=
200
;
};
...
...
server/src/api/hub/index.js
View file @
e4e0fa2
...
...
@@ -12,6 +12,14 @@ const hub = new Router();
hub
.
post
(
'/'
,
hubCtrl
.
hubConnect
);
/**
* 허브 등록 해제
* request parameter : x
* url : http://localhost:4000/api/hub/:hubId
* return : null
*/
hub
.
delete
(
'/:hubId'
,
hubCtrl
.
hubDisconnect
);
/**
* 로그인한 유저의 허브 목록 가져오기
* request parameter : X
* url : http://localhost:4000/api/hub
...
...
@@ -20,11 +28,13 @@ hub.post('/', hubCtrl.hubConnect);
hub
.
get
(
'/'
,
hubCtrl
.
getHubList
);
/**
*
허브 등록 해제
* request parameter :
x
*
로그인한 유저의 특정 허브 이름 변경
* request parameter :
hubId, hubNm
* url : http://localhost:4000/api/hub/:hubId
* return : null
*/
hub
.
delete
(
'/:hubId'
,
hubCtrl
.
hubDisconnect
);
hub
.
patch
(
'/:hubId'
,
hubCtrl
.
setHubName
);
module
.
exports
=
hub
;
\ No newline at end of file
...
...
server/src/models/bottle.js
View file @
e4e0fa2
...
...
@@ -5,6 +5,7 @@ const Schema = mongoose.Schema;
const
BottleSchema
=
new
Schema
({
bottleId
:
{
type
:
Number
,
required
:
true
,
unique
:
true
},
hubId
:
{
type
:
Number
,
required
:
true
,
ref
:
'Hub'
,
},
bottleNm
:
{
type
:
String
,
required
:
true
,
maxlength
:
10
,
},
});
BottleSchema
.
statics
.
findByBottleId
=
function
(
bottleId
)
{
...
...
@@ -23,5 +24,9 @@ BottleSchema.methods.getHubId = function() {
return
this
.
hubId
;
};
BottleSchema
.
methods
.
setBottleNm
=
function
(
bottleNm
)
{
this
.
bottleNm
=
bottleNm
;
}
module
.
exports
=
mongoose
.
model
(
'Bottle'
,
BottleSchema
);
\ No newline at end of file
...
...
server/src/models/hub.js
View file @
e4e0fa2
...
...
@@ -6,6 +6,7 @@ const HubSchema = new Schema ({
hubId
:
{
type
:
Number
,
required
:
true
,
unique
:
true
},
hosting
:
{
type
:
Object
,
default
:
null
},
userId
:
{
type
:
String
,
default
:
null
,
ref
:
'User'
,
lowercase
:
true
,
},
hubNm
:
{
type
:
String
,
required
:
true
,
maxlength
:
10
,
},
});
HubSchema
.
statics
.
findByHubId
=
function
(
hubId
)
{
...
...
Please
register
or
login
to post a comment