Showing
8 changed files
with
86 additions
and
22 deletions
... | @@ -6,7 +6,6 @@ const bodyparser = require('koa-bodyparser'); | ... | @@ -6,7 +6,6 @@ const bodyparser = require('koa-bodyparser'); |
6 | 6 | ||
7 | const Mongoose = require('mongoose'); | 7 | const Mongoose = require('mongoose'); |
8 | const api = require('./src/api'); | 8 | const api = require('./src/api'); |
9 | -const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo'); | ||
10 | const MqttServer = require('./src/util/MqttServer'); | 9 | const MqttServer = require('./src/util/MqttServer'); |
11 | const BatchSystem = require('./src/util/Batch'); | 10 | const BatchSystem = require('./src/util/Batch'); |
12 | 11 | ||
... | @@ -25,7 +24,7 @@ Mongoose.connect(MONGO_URL, { | ... | @@ -25,7 +24,7 @@ Mongoose.connect(MONGO_URL, { |
25 | useCreateIndex : true | 24 | useCreateIndex : true |
26 | }).then(() => { | 25 | }).then(() => { |
27 | console.log('\x1b[1;32mMongo DB is connected : ', MONGO_URL, '\x1b[0m'); | 26 | console.log('\x1b[1;32mMongo DB is connected : ', MONGO_URL, '\x1b[0m'); |
28 | - // updateMedicineInfo.updateMedicineInfo(); | 27 | + BatchSystem.updateMedicineData(); |
29 | }).catch(e => { | 28 | }).catch(e => { |
30 | console.log(e); | 29 | console.log(e); |
31 | }); | 30 | }); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -17,7 +17,9 @@ | ... | @@ -17,7 +17,9 @@ |
17 | "author": "박권수", | 17 | "author": "박권수", |
18 | "license": "ISC", | 18 | "license": "ISC", |
19 | "dependencies": { | 19 | "dependencies": { |
20 | + "@google-cloud/storage": "^5.14.2", | ||
20 | "@koa/cors": "^3.1.0", | 21 | "@koa/cors": "^3.1.0", |
22 | + "koa-body": "^4.2.0", | ||
21 | "moment": "^2.29.1", | 23 | "moment": "^2.29.1", |
22 | "moment-timezone": "^0.5.33", | 24 | "moment-timezone": "^0.5.33", |
23 | "mqtt": "^4.2.6", | 25 | "mqtt": "^4.2.6", | ... | ... |
... | @@ -7,6 +7,8 @@ const Joi = require('joi'); | ... | @@ -7,6 +7,8 @@ const Joi = require('joi'); |
7 | const jwt = require('jsonwebtoken'); | 7 | const jwt = require('jsonwebtoken'); |
8 | const axios = require('axios'); | 8 | const axios = require('axios'); |
9 | 9 | ||
10 | +const { Storage } = require('@google-cloud/storage'); | ||
11 | +const GoogleStorageUrl = 'https://storage.googleapis.com/'; | ||
10 | 12 | ||
11 | exports.register = async(ctx) => { | 13 | exports.register = async(ctx) => { |
12 | const { | 14 | const { |
... | @@ -95,17 +97,38 @@ exports.doctorRegister = async ctx => { | ... | @@ -95,17 +97,38 @@ exports.doctorRegister = async ctx => { |
95 | userId, | 97 | userId, |
96 | password, | 98 | password, |
97 | passwordCheck, | 99 | passwordCheck, |
98 | - info, | 100 | + |
101 | + contact, | ||
102 | + hospitalNm, | ||
103 | + hospitalAddr, | ||
104 | + doctorType, | ||
105 | + doctorNm, | ||
99 | } = ctx.request.body; | 106 | } = ctx.request.body; |
100 | 107 | ||
108 | + const { doctorInfoFile } = ctx.request.files; | ||
109 | + | ||
110 | + const info = { | ||
111 | + contact, | ||
112 | + hospitalAddr, | ||
113 | + hospitalNm, | ||
114 | + doctorType, | ||
115 | + doctorNm, | ||
116 | + doctorLicense : '', | ||
117 | + }; | ||
118 | + | ||
101 | const schema = Joi.object().keys({ | 119 | const schema = Joi.object().keys({ |
102 | userId : Joi.string().email().max(50).required(), | 120 | userId : Joi.string().email().max(50).required(), |
103 | password : Joi.string().required(), | 121 | password : Joi.string().required(), |
104 | passwordCheck : Joi.string().required(), | 122 | passwordCheck : Joi.string().required(), |
105 | - info : Joi.object().required(), | 123 | + doctorInfoFile : Joi.object().required(), |
106 | - }) | 124 | + }); |
107 | - | 125 | + |
108 | - const result = schema.validate(ctx.request.body); | 126 | + const result = schema.validate({ |
127 | + userId, | ||
128 | + password, | ||
129 | + passwordCheck, | ||
130 | + doctorInfoFile, | ||
131 | + }); | ||
109 | if(result.error || password !== passwordCheck) { | 132 | if(result.error || password !== passwordCheck) { |
110 | ctx.status = 400; | 133 | ctx.status = 400; |
111 | ctx.body = { | 134 | ctx.body = { |
... | @@ -145,19 +168,31 @@ exports.doctorRegister = async ctx => { | ... | @@ -145,19 +168,31 @@ exports.doctorRegister = async ctx => { |
145 | }); | 168 | }); |
146 | 169 | ||
147 | await doctor.setPassword(password); | 170 | await doctor.setPassword(password); |
171 | + doctor.save(); | ||
148 | 172 | ||
149 | - const doctorInfo = new DoctorInfo({ | ||
150 | - doctorId : userId, | ||
151 | - info, | ||
152 | - useYn : 'W', | ||
153 | - }); | ||
154 | 173 | ||
174 | + const destination = userId + '_' + doctorInfoFile.name; | ||
175 | + const storage = new Storage(); | ||
176 | + storage.bucket('doctor-info').upload(doctorInfoFile.path, { | ||
177 | + destination, | ||
178 | + }, (err, file, res) => { | ||
179 | + if(err) console.log('Fail to upload Doctor License'); | ||
180 | + else { | ||
181 | + info.doctorLicense = GoogleStorageUrl + `${res.bucket}/${res.name}`; | ||
182 | + console.log('Success to Upload Doctor License!'); | ||
183 | + } | ||
155 | 184 | ||
156 | - doctor.save(); | 185 | + const doctorInfo = new DoctorInfo({ |
157 | - doctorInfo.save(); | 186 | + doctorId : userId, |
187 | + info, | ||
188 | + useYn : 'W', | ||
189 | + }); | ||
190 | + | ||
191 | + doctorInfo.save(); | ||
192 | + }); | ||
158 | 193 | ||
159 | ctx.status = 201; | 194 | ctx.status = 201; |
160 | - | 195 | + |
161 | } | 196 | } |
162 | 197 | ||
163 | exports.login = async(ctx) => { | 198 | exports.login = async(ctx) => { | ... | ... |
1 | const Router = require('koa-router') | 1 | const Router = require('koa-router') |
2 | +const KoaBody = require('koa-body')({multipart : true}); | ||
2 | const authCtrl = require('./auth.ctrl') | 3 | const authCtrl = require('./auth.ctrl') |
3 | 4 | ||
4 | const auth = new Router() | 5 | const auth = new Router() |
... | @@ -22,10 +23,10 @@ auth.get('/hospital', authCtrl.searchHospital); | ... | @@ -22,10 +23,10 @@ auth.get('/hospital', authCtrl.searchHospital); |
22 | /** | 23 | /** |
23 | * 회원가입 (email type) : 의사 회원가입 | 24 | * 회원가입 (email type) : 의사 회원가입 |
24 | * url : http://localhost:4000/api/auth/register/doctor | 25 | * url : http://localhost:4000/api/auth/register/doctor |
25 | - * request parameter : userId, password, passwordCheck, doctorInfo | 26 | + * request parameter : userId, password, passwordCheck, doctorInfo(File) |
26 | * return : null | 27 | * return : null |
27 | */ | 28 | */ |
28 | - auth.post('/register/doctor', authCtrl.doctorRegister) | 29 | + auth.post('/register/doctor', KoaBody, authCtrl.doctorRegister) |
29 | 30 | ||
30 | /** | 31 | /** |
31 | * 로그인 (email type) | 32 | * 로그인 (email type) | ... | ... |
1 | const User = require('../../models/user'); | 1 | const User = require('../../models/user'); |
2 | const DoctorInfo = require('../../models/doctorInfo'); | 2 | const DoctorInfo = require('../../models/doctorInfo'); |
3 | -const Profile = require('../../models/profile'); | ||
4 | const jwt = require('jsonwebtoken'); | 3 | const jwt = require('jsonwebtoken'); |
5 | 4 | ||
5 | +const { Storage } = require('@google-cloud/storage'); | ||
6 | + | ||
7 | + | ||
6 | /** | 8 | /** |
7 | * 의사 회원가입을 요청한 회원 리스트를 확인한다. | 9 | * 의사 회원가입을 요청한 회원 리스트를 확인한다. |
8 | * http methods : get | 10 | * http methods : get |
... | @@ -108,9 +110,25 @@ exports.getDoctorRegReqDetail = async ctx => { | ... | @@ -108,9 +110,25 @@ exports.getDoctorRegReqDetail = async ctx => { |
108 | return; | 110 | return; |
109 | } | 111 | } |
110 | 112 | ||
113 | + const fileName = doctorInfo.info.doctorLicense.split('/').pop(); | ||
114 | + const file = new Storage().bucket('doctor-info').file(fileName); | ||
115 | + const option = { | ||
116 | + version : 'v4', | ||
117 | + expires : Date.now() + 1000 * 60 * 15, | ||
118 | + action : 'read', | ||
119 | + }; | ||
120 | + | ||
121 | + const [signedUrl] = file ? await file.getSignedUrl(option) : ['']; | ||
122 | + | ||
111 | ctx.status = 200; | 123 | ctx.status = 200; |
112 | ctx.body = { | 124 | ctx.body = { |
113 | - doctorInfo, | 125 | + doctorInfo : { |
126 | + ...doctorInfo._doc, | ||
127 | + info : { | ||
128 | + ...doctorInfo.info, | ||
129 | + doctorLicense : signedUrl, | ||
130 | + }, | ||
131 | + }, | ||
114 | }; | 132 | }; |
115 | 133 | ||
116 | } catch (e) { | 134 | } catch (e) { | ... | ... |
... | @@ -13,6 +13,8 @@ | ... | @@ -13,6 +13,8 @@ |
13 | const Hub = require('../models/hub'); | 13 | const Hub = require('../models/hub'); |
14 | const Bottle = require('../models/bottle'); | 14 | const Bottle = require('../models/bottle'); |
15 | const BottleMedicine = require('../models/bottleMedicine'); | 15 | const BottleMedicine = require('../models/bottleMedicine'); |
16 | + | ||
17 | +const updateMedicineInfo = require('../lib/UpdatingMedicineInfo'); | ||
16 | 18 | ||
17 | 19 | ||
18 | // //매년 1월 1일 00시 00분에 1살씩 추가 | 20 | // //매년 1월 1일 00시 00분에 1살씩 추가 |
... | @@ -28,9 +30,16 @@ | ... | @@ -28,9 +30,16 @@ |
28 | // timezone : 'Asia/Tokyo', | 30 | // timezone : 'Asia/Tokyo', |
29 | // }); | 31 | // }); |
30 | // }; | 32 | // }; |
31 | - | 33 | + |
32 | - //dosage에 따라, Push Notification을 발송한다. | 34 | +//매월 1일 0시 0분에 약 정보 업데이트 |
33 | - //아침 8시, 점심 12시, 저녁 6시에 한번씩 발송 | 35 | +exports.updateMedicineData = async () => { |
36 | + cron.schedule('0 0 0 1 * *', () => { | ||
37 | + updateMedicineInfo.updateMedicineInfo(); | ||
38 | + }); | ||
39 | +}; | ||
40 | + | ||
41 | +//dosage에 따라, Push Notification을 발송한다. | ||
42 | +//아침 8시, 점심 12시, 저녁 6시에 한번씩 발송 | ||
34 | exports.PushNotifyByDosage = async() => { | 43 | exports.PushNotifyByDosage = async() => { |
35 | 44 | ||
36 | //매일 아침 8시 : 복용량 상관 없이 보냄 | 45 | //매일 아침 8시 : 복용량 상관 없이 보냄 | ... | ... |
This diff could not be displayed because it is too large.
-
Please register or login to post a comment