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-09 03:21:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
859216332d27558f2a544465115cd026597719a9
85921633
1 parent
55f9e222
styled. code style is changed
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
15 deletions
server/src/lib/DataProcess.js
server/src/models/bottle.js
server/src/models/hub.js
server/src/models/medicine.js
server/src/models/user.js
server/src/lib/DataProcess.js
View file @
8592163
...
...
@@ -3,7 +3,7 @@ const Bottle = require('../models/bottle');
//Hub topic : bottle/bottleId
//Hub로부터 받은 message : 개폐여부/온도/습도/초음파센서
exports
.
factoring
=
(
topic
,
message
)
=>
{
const
bottleId
=
topic
.
split
(
'/'
)[
1
]
;
const
bottleId
=
parseInt
(
topic
.
split
(
'/'
)[
1
])
;
const
data
=
message
.
split
(
'/'
);
const
[
isOpen
,
temperature
,
humidity
,
balance
]
=
data
;
...
...
@@ -40,6 +40,22 @@ exports.bottleInfoUpdate = async(data) => {
}
//해당 MQTT Broker(client)에 bottleId의 정보에 관한 message를 발행한다.
exports
.
dataPublishg
=
(
client
,
bottleId
)
=>
{
exports
.
dataPublishing
=
async
(
client
,
bottleId
)
=>
{
const
topic
=
'bottle/'
.
concat
(
bottleId
);
const
bottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
const
recentOpen
=
await
bottle
.
getRecentOpenDate
();
const
message
=
await
transDate
(
recentOpen
);
client
.
publish
(
topic
,
message
,
()
=>
{
console
.
log
(
'topic : '
,
topic
,
'message : '
,
message
);
})
}
//날짜를 yymmdd로 변환해주는 함수
const
transDate
=
(
date
)
=>
{
return
String
(
date
.
getFullYear
()).
substr
(
2
,
2
)
+
(
date
.
getMonth
()
+
1
<
10
?
'0'
+
String
(
date
.
getMonth
()
+
1
)
:
String
(
date
.
getMonth
()
+
1
))
+
(
date
.
getDate
()
<
10
?
'0'
+
String
(
date
.
getDate
())
:
String
(
date
.
getDate
()));
}
\ No newline at end of file
...
...
server/src/models/bottle.js
View file @
8592163
...
...
@@ -16,4 +16,28 @@ BottleSchema.statics.findByBottleId = function(bottleId) {
return
this
.
findOne
({
bottleId
});
};
BottleSchema
.
methods
.
getRecentOpenDate
=
function
()
{
return
this
.
recentOpen
;
};
BottleSchema
.
methods
.
getTemperature
=
function
()
{
return
this
.
temperature
;
};
BottleSchema
.
methods
.
getHumidity
=
function
()
{
return
this
.
humidity
;
};
BottleSchema
.
methods
.
getBalance
=
function
()
{
return
this
.
balance
;
};
BottleSchema
.
methods
.
getMedicineId
=
function
()
{
return
this
.
medicineId
;
};
BottleSchema
.
methods
.
getHubId
=
function
()
{
return
this
.
hubId
;
};
module
.
exports
=
mongoose
.
model
(
'Bottle'
,
BottleSchema
);
\ No newline at end of file
...
...
server/src/models/hub.js
View file @
8592163
...
...
@@ -10,22 +10,22 @@ const HubSchema = new Schema ({
HubSchema
.
statics
.
findByHubId
=
function
(
hubId
)
{
return
this
.
findOne
({
hubId
})
}
}
;
HubSchema
.
methods
.
setHubHost
=
function
(
hosting
)
{
this
.
hosting
=
hosting
;
}
}
;
HubSchema
.
methods
.
getHubHost
=
function
()
{
return
this
.
hosting
;
}
}
;
HubSchema
.
methods
.
setHub_UserId
=
function
(
userId
)
{
this
.
userId
=
userId
;
}
}
;
HubSchema
.
methods
.
getHub_UserId
=
function
()
{
return
this
.
userId
;
}
}
;
module
.
exports
=
mongoose
.
model
(
'Hub'
,
HubSchema
);
\ No newline at end of file
...
...
server/src/models/medicine.js
View file @
8592163
...
...
@@ -39,9 +39,9 @@ MedicineSchema.statics.findByTarget = async function(target) {
return
result
;
};
MedicineSchema
.
statics
.
findBy
Id
=
async
function
(
medicineId
)
{
MedicineSchema
.
statics
.
findBy
MedicineId
=
function
(
medicineId
)
{
return
this
.
findOne
({
medicineId
})
}
}
;
module
.
exports
=
mongoose
.
model
(
'Medicine'
,
MedicineSchema
);
\ No newline at end of file
...
...
server/src/models/user.js
View file @
8592163
...
...
@@ -7,21 +7,21 @@ const Schema = mongoose.Schema;
const
UserSchema
=
new
Schema
({
userId
:
{
type
:
String
,
require
:
true
,
unique
:
true
},
hashedPassword
:
{
type
:
String
,
default
:
null
}
})
})
;
UserSchema
.
methods
.
setPassword
=
async
function
(
password
)
{
const
hash
=
await
bycrypt
(
password
,
10
);
this
.
hashedPassword
=
hash
;
}
}
;
UserSchema
.
methods
.
checkPassword
=
async
function
(
password
)
{
const
result
=
await
bycrypt
.
compare
(
password
,
this
.
hashedPassword
)
return
result
;
}
}
;
UserSchema
.
statics
.
findByUserId
=
async
function
(
userId
)
{
return
this
.
findOne
({
userId
});
}
return
this
.
findOne
({
userId
});
}
;
UserSchema
.
methods
.
generateToken
=
function
()
{
const
token
=
jwt
.
sign
(
...
...
@@ -33,6 +33,6 @@ UserSchema.methods.generateToken = function() {
{
expiresIn
:
'30d'
}
);
return
token
;
}
}
;
module
.
exports
=
mongoose
.
model
(
"User"
,
UserSchema
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment