박권수

styled. code style is changed

...@@ -3,7 +3,7 @@ const Bottle = require('../models/bottle'); ...@@ -3,7 +3,7 @@ const Bottle = require('../models/bottle');
3 //Hub topic : bottle/bottleId 3 //Hub topic : bottle/bottleId
4 //Hub로부터 받은 message : 개폐여부/온도/습도/초음파센서 4 //Hub로부터 받은 message : 개폐여부/온도/습도/초음파센서
5 exports.factoring = (topic, message) => { 5 exports.factoring = (topic, message) => {
6 - const bottleId = topic.split('/')[1]; 6 + const bottleId = parseInt(topic.split('/')[1]);
7 const data = message.split('/'); 7 const data = message.split('/');
8 const [isOpen, temperature, humidity, balance] = data; 8 const [isOpen, temperature, humidity, balance] = data;
9 9
...@@ -40,6 +40,22 @@ exports.bottleInfoUpdate = async(data) => { ...@@ -40,6 +40,22 @@ exports.bottleInfoUpdate = async(data) => {
40 } 40 }
41 41
42 //해당 MQTT Broker(client)에 bottleId의 정보에 관한 message를 발행한다. 42 //해당 MQTT Broker(client)에 bottleId의 정보에 관한 message를 발행한다.
43 -exports.dataPublishg = (client, bottleId) => { 43 +exports.dataPublishing = async(client, bottleId) => {
44 + const topic = 'bottle/'.concat(bottleId);
44 45
46 + const bottle = await Bottle.findByBottleId(bottleId);
47 + const recentOpen = await bottle.getRecentOpenDate();
48 +
49 + const message = await transDate(recentOpen);
50 +
51 + client.publish(topic, message, () => {
52 + console.log('topic : ', topic, 'message : ', message);
53 + })
54 +}
55 +
56 +//날짜를 yymmdd로 변환해주는 함수
57 +const transDate = (date) => {
58 + return String(date.getFullYear()).substr(2, 2)
59 + + (date.getMonth() + 1 < 10 ? '0' + String(date.getMonth() + 1) : String(date.getMonth() + 1))
60 + + (date.getDate() < 10 ? '0' + String(date.getDate()) : String(date.getDate()));
45 } 61 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,4 +16,28 @@ BottleSchema.statics.findByBottleId = function(bottleId) { ...@@ -16,4 +16,28 @@ BottleSchema.statics.findByBottleId = function(bottleId) {
16 return this.findOne({ bottleId }); 16 return this.findOne({ bottleId });
17 }; 17 };
18 18
19 +BottleSchema.methods.getRecentOpenDate = function() {
20 + return this.recentOpen;
21 +};
22 +
23 +BottleSchema.methods.getTemperature = function() {
24 + return this.temperature;
25 +};
26 +
27 +BottleSchema.methods.getHumidity = function() {
28 + return this.humidity;
29 +};
30 +
31 +BottleSchema.methods.getBalance = function() {
32 + return this.balance;
33 +};
34 +
35 +BottleSchema.methods.getMedicineId = function() {
36 + return this.medicineId;
37 +};
38 +
39 +BottleSchema.methods.getHubId = function() {
40 + return this.hubId;
41 +};
42 +
19 module.exports = mongoose.model('Bottle', BottleSchema); 43 module.exports = mongoose.model('Bottle', BottleSchema);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -10,22 +10,22 @@ const HubSchema = new Schema ({ ...@@ -10,22 +10,22 @@ const HubSchema = new Schema ({
10 10
11 HubSchema.statics.findByHubId = function(hubId) { 11 HubSchema.statics.findByHubId = function(hubId) {
12 return this.findOne({ hubId }) 12 return this.findOne({ hubId })
13 -} 13 +};
14 14
15 HubSchema.methods.setHubHost = function(hosting) { 15 HubSchema.methods.setHubHost = function(hosting) {
16 this.hosting = hosting; 16 this.hosting = hosting;
17 -} 17 +};
18 18
19 HubSchema.methods.getHubHost = function() { 19 HubSchema.methods.getHubHost = function() {
20 return this.hosting; 20 return this.hosting;
21 -} 21 +};
22 22
23 HubSchema.methods.setHub_UserId = function(userId) { 23 HubSchema.methods.setHub_UserId = function(userId) {
24 this.userId = userId; 24 this.userId = userId;
25 -} 25 +};
26 26
27 HubSchema.methods.getHub_UserId = function() { 27 HubSchema.methods.getHub_UserId = function() {
28 return this.userId; 28 return this.userId;
29 -} 29 +};
30 30
31 module.exports = mongoose.model('Hub', HubSchema); 31 module.exports = mongoose.model('Hub', HubSchema);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -39,9 +39,9 @@ MedicineSchema.statics.findByTarget = async function(target) { ...@@ -39,9 +39,9 @@ MedicineSchema.statics.findByTarget = async function(target) {
39 return result; 39 return result;
40 }; 40 };
41 41
42 -MedicineSchema.statics.findById = async function(medicineId) { 42 +MedicineSchema.statics.findByMedicineId = function(medicineId) {
43 return this.findOne({ medicineId }) 43 return this.findOne({ medicineId })
44 -} 44 +};
45 45
46 46
47 module.exports = mongoose.model('Medicine', MedicineSchema); 47 module.exports = mongoose.model('Medicine', MedicineSchema);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,21 +7,21 @@ const Schema = mongoose.Schema; ...@@ -7,21 +7,21 @@ const Schema = mongoose.Schema;
7 const UserSchema = new Schema({ 7 const UserSchema = new Schema({
8 userId : { type: String, require : true, unique : true }, 8 userId : { type: String, require : true, unique : true },
9 hashedPassword : { type : String, default : null } 9 hashedPassword : { type : String, default : null }
10 -}) 10 +});
11 11
12 UserSchema.methods.setPassword = async function(password) { 12 UserSchema.methods.setPassword = async function(password) {
13 const hash = await bycrypt(password, 10); 13 const hash = await bycrypt(password, 10);
14 this.hashedPassword = hash; 14 this.hashedPassword = hash;
15 -} 15 +};
16 16
17 UserSchema.methods.checkPassword = async function(password) { 17 UserSchema.methods.checkPassword = async function(password) {
18 const result = await bycrypt.compare(password, this.hashedPassword) 18 const result = await bycrypt.compare(password, this.hashedPassword)
19 return result; 19 return result;
20 -} 20 +};
21 21
22 UserSchema.statics.findByUserId = async function(userId) { 22 UserSchema.statics.findByUserId = async function(userId) {
23 - return this.findOne({userId}); 23 + return this.findOne({ userId });
24 -} 24 +};
25 25
26 UserSchema.methods.generateToken = function() { 26 UserSchema.methods.generateToken = function() {
27 const token = jwt.sign ( 27 const token = jwt.sign (
...@@ -33,6 +33,6 @@ UserSchema.methods.generateToken = function() { ...@@ -33,6 +33,6 @@ UserSchema.methods.generateToken = function() {
33 { expiresIn : '30d' } 33 { expiresIn : '30d' }
34 ); 34 );
35 return token; 35 return token;
36 -} 36 +};
37 37
38 module.exports = mongoose.model("User", UserSchema); 38 module.exports = mongoose.model("User", UserSchema);
...\ No newline at end of file ...\ No newline at end of file
......