박권수

styled. code style is changed

......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -39,9 +39,9 @@ MedicineSchema.statics.findByTarget = async function(target) {
return result;
};
MedicineSchema.statics.findById = async function(medicineId) {
MedicineSchema.statics.findByMedicineId = function(medicineId) {
return this.findOne({ medicineId })
}
};
module.exports = mongoose.model('Medicine', MedicineSchema);
\ No newline at end of file
......
......@@ -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
......