Showing
2 changed files
with
44 additions
and
11 deletions
1 | //허브(Mqtt Broker)등록 및 삭제 | 1 | //허브(Mqtt Broker)등록 및 삭제 |
2 | const Hub = require('../../models/hub'); | 2 | const Hub = require('../../models/hub'); |
3 | +const Mqtt = require('../../lib/MqttModule'); | ||
3 | 4 | ||
4 | -exports.hubRegister = async(ctx) => { | 5 | +exports.hubRegister = async (ctx) => { |
5 | - ctx.body = 'hubRegister' | 6 | + const { host, port, hubId, topic } = ctx.request.body; |
7 | + | ||
8 | + const hub = new Hub({ | ||
9 | + hubId, | ||
10 | + hosting : { | ||
11 | + host, | ||
12 | + port | ||
13 | + } | ||
14 | + }); | ||
15 | + | ||
16 | + await Hub.findOneAndUpdate({ | ||
17 | + hubId | ||
18 | + }, hub, { | ||
19 | + upsert : true | ||
20 | + }); | ||
21 | + | ||
22 | + const client = Mqtt.mqttOn({ host, port }); | ||
23 | + Mqtt.mqttSubscribe(client, topic); | ||
24 | + | ||
25 | + ctx.body = 'host :' + host; | ||
26 | + ctx.status = 200; | ||
6 | } | 27 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,27 +2,39 @@ | ... | @@ -2,27 +2,39 @@ |
2 | const Medicine = require('../../models/medicine'); | 2 | const Medicine = require('../../models/medicine'); |
3 | 3 | ||
4 | exports.medicineSearch = async(ctx) => { | 4 | exports.medicineSearch = async(ctx) => { |
5 | + const { name, company, target } = ctx.request.body; | ||
6 | + | ||
7 | + let result = null; | ||
8 | + | ||
9 | + if (name && name !== '' && name !== undefined) | ||
10 | + result = await medicineSearch_ByName(name); | ||
11 | + | ||
12 | + else if (company && company !== '' && company !== undefined) | ||
13 | + result = await medicineSearch_ByCompany(company); | ||
14 | + | ||
15 | + else if (target && target !== '' && target !== undefined) | ||
16 | + result = await medicineSearch_ByTarget(target); | ||
17 | + | ||
5 | ctx.body = { | 18 | ctx.body = { |
6 | - medicineSearch : 'search..' | 19 | + totalItem : result.length, |
20 | + result | ||
7 | } | 21 | } |
8 | } | 22 | } |
9 | 23 | ||
10 | //이름으로 약 검색 | 24 | //이름으로 약 검색 |
11 | const medicineSearch_ByName = async(name) => { | 25 | const medicineSearch_ByName = async(name) => { |
12 | - | 26 | + const result = await Medicine.findByName(name); |
27 | + return result; | ||
13 | } | 28 | } |
14 | 29 | ||
15 | //제조사명으로 약 검색 | 30 | //제조사명으로 약 검색 |
16 | const medicineSearch_ByCompany = async(company) => { | 31 | const medicineSearch_ByCompany = async(company) => { |
17 | - | 32 | + const result = await Medicine.findByCompany(company); |
18 | -} | 33 | + return result; |
19 | - | ||
20 | -//효능으로 약 검색 | ||
21 | -const medicineSearch_ByEfficacy = async(efficacy) => { | ||
22 | - | ||
23 | } | 34 | } |
24 | 35 | ||
25 | //타겟 병명으로 약 검색 | 36 | //타겟 병명으로 약 검색 |
26 | const medicineSearch_ByTarget = async(target) => { | 37 | const medicineSearch_ByTarget = async(target) => { |
27 | - | 38 | + const result = await Medicine.findByTarget(target); |
39 | + return result; | ||
28 | } | 40 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment