박권수

feat. mqtt protocol and db connect

//허브(Mqtt Broker)등록 및 삭제
const Hub = require('../../models/hub');
const Mqtt = require('../../lib/MqttModule');
exports.hubRegister = async(ctx) => {
ctx.body = 'hubRegister'
exports.hubRegister = async (ctx) => {
const { host, port, hubId, topic } = ctx.request.body;
const hub = new Hub({
hubId,
hosting : {
host,
port
}
});
await Hub.findOneAndUpdate({
hubId
}, hub, {
upsert : true
});
const client = Mqtt.mqttOn({ host, port });
Mqtt.mqttSubscribe(client, topic);
ctx.body = 'host :' + host;
ctx.status = 200;
}
\ No newline at end of file
......
......@@ -2,27 +2,39 @@
const Medicine = require('../../models/medicine');
exports.medicineSearch = async(ctx) => {
const { name, company, target } = ctx.request.body;
let result = null;
if (name && name !== '' && name !== undefined)
result = await medicineSearch_ByName(name);
else if (company && company !== '' && company !== undefined)
result = await medicineSearch_ByCompany(company);
else if (target && target !== '' && target !== undefined)
result = await medicineSearch_ByTarget(target);
ctx.body = {
medicineSearch : 'search..'
totalItem : result.length,
result
}
}
//이름으로 약 검색
const medicineSearch_ByName = async(name) => {
const result = await Medicine.findByName(name);
return result;
}
//제조사명으로 약 검색
const medicineSearch_ByCompany = async(company) => {
}
//효능으로 약 검색
const medicineSearch_ByEfficacy = async(efficacy) => {
const result = await Medicine.findByCompany(company);
return result;
}
//타겟 병명으로 약 검색
const medicineSearch_ByTarget = async(target) => {
const result = await Medicine.findByTarget(target);
return result;
}
\ No newline at end of file
......