박권수

feat. 의사 자격 인증 : 번호입력 -> GCS 파일 업로드 / Batch로 약 정보 매달 1일 업데이트

......@@ -6,7 +6,6 @@ const bodyparser = require('koa-bodyparser');
const Mongoose = require('mongoose');
const api = require('./src/api');
const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo');
const MqttServer = require('./src/util/MqttServer');
const BatchSystem = require('./src/util/Batch');
......@@ -25,7 +24,7 @@ Mongoose.connect(MONGO_URL, {
useCreateIndex : true
}).then(() => {
console.log('\x1b[1;32mMongo DB is connected : ', MONGO_URL, '\x1b[0m');
// updateMedicineInfo.updateMedicineInfo();
BatchSystem.updateMedicineData();
}).catch(e => {
console.log(e);
});
......
This diff is collapsed. Click to expand it.
......@@ -17,7 +17,9 @@
"author": "박권수",
"license": "ISC",
"dependencies": {
"@google-cloud/storage": "^5.14.2",
"@koa/cors": "^3.1.0",
"koa-body": "^4.2.0",
"moment": "^2.29.1",
"moment-timezone": "^0.5.33",
"mqtt": "^4.2.6",
......
......@@ -7,6 +7,8 @@ const Joi = require('joi');
const jwt = require('jsonwebtoken');
const axios = require('axios');
const { Storage } = require('@google-cloud/storage');
const GoogleStorageUrl = 'https://storage.googleapis.com/';
exports.register = async(ctx) => {
const {
......@@ -95,17 +97,38 @@ exports.doctorRegister = async ctx => {
userId,
password,
passwordCheck,
info,
contact,
hospitalNm,
hospitalAddr,
doctorType,
doctorNm,
} = ctx.request.body;
const { doctorInfoFile } = ctx.request.files;
const info = {
contact,
hospitalAddr,
hospitalNm,
doctorType,
doctorNm,
doctorLicense : '',
};
const schema = Joi.object().keys({
userId : Joi.string().email().max(50).required(),
password : Joi.string().required(),
passwordCheck : Joi.string().required(),
info : Joi.object().required(),
})
const result = schema.validate(ctx.request.body);
doctorInfoFile : Joi.object().required(),
});
const result = schema.validate({
userId,
password,
passwordCheck,
doctorInfoFile,
});
if(result.error || password !== passwordCheck) {
ctx.status = 400;
ctx.body = {
......@@ -145,19 +168,31 @@ exports.doctorRegister = async ctx => {
});
await doctor.setPassword(password);
doctor.save();
const doctorInfo = new DoctorInfo({
doctorId : userId,
info,
useYn : 'W',
});
const destination = userId + '_' + doctorInfoFile.name;
const storage = new Storage();
storage.bucket('doctor-info').upload(doctorInfoFile.path, {
destination,
}, (err, file, res) => {
if(err) console.log('Fail to upload Doctor License');
else {
info.doctorLicense = GoogleStorageUrl + `${res.bucket}/${res.name}`;
console.log('Success to Upload Doctor License!');
}
doctor.save();
doctorInfo.save();
const doctorInfo = new DoctorInfo({
doctorId : userId,
info,
useYn : 'W',
});
doctorInfo.save();
});
ctx.status = 201;
}
exports.login = async(ctx) => {
......
const Router = require('koa-router')
const KoaBody = require('koa-body')({multipart : true});
const authCtrl = require('./auth.ctrl')
const auth = new Router()
......@@ -22,10 +23,10 @@ auth.get('/hospital', authCtrl.searchHospital);
/**
* 회원가입 (email type) : 의사 회원가입
* url : http://localhost:4000/api/auth/register/doctor
* request parameter : userId, password, passwordCheck, doctorInfo
* request parameter : userId, password, passwordCheck, doctorInfo(File)
* return : null
*/
auth.post('/register/doctor', authCtrl.doctorRegister)
auth.post('/register/doctor', KoaBody, authCtrl.doctorRegister)
/**
* 로그인 (email type)
......
const User = require('../../models/user');
const DoctorInfo = require('../../models/doctorInfo');
const Profile = require('../../models/profile');
const jwt = require('jsonwebtoken');
const { Storage } = require('@google-cloud/storage');
/**
* 의사 회원가입을 요청한 회원 리스트를 확인한다.
* http methods : get
......@@ -108,9 +110,25 @@ exports.getDoctorRegReqDetail = async ctx => {
return;
}
const fileName = doctorInfo.info.doctorLicense.split('/').pop();
const file = new Storage().bucket('doctor-info').file(fileName);
const option = {
version : 'v4',
expires : Date.now() + 1000 * 60 * 15,
action : 'read',
};
const [signedUrl] = file ? await file.getSignedUrl(option) : [''];
ctx.status = 200;
ctx.body = {
doctorInfo,
doctorInfo : {
...doctorInfo._doc,
info : {
...doctorInfo.info,
doctorLicense : signedUrl,
},
},
};
} catch (e) {
......
......@@ -13,6 +13,8 @@
const Hub = require('../models/hub');
const Bottle = require('../models/bottle');
const BottleMedicine = require('../models/bottleMedicine');
const updateMedicineInfo = require('../lib/UpdatingMedicineInfo');
// //매년 1월 1일 00시 00분에 1살씩 추가
......@@ -28,9 +30,16 @@
// timezone : 'Asia/Tokyo',
// });
// };
//dosage에 따라, Push Notification을 발송한다.
//아침 8시, 점심 12시, 저녁 6시에 한번씩 발송
//매월 1일 0시 0분에 약 정보 업데이트
exports.updateMedicineData = async () => {
cron.schedule('0 0 0 1 * *', () => {
updateMedicineInfo.updateMedicineInfo();
});
};
//dosage에 따라, Push Notification을 발송한다.
//아침 8시, 점심 12시, 저녁 6시에 한번씩 발송
exports.PushNotifyByDosage = async() => {
//매일 아침 8시 : 복용량 상관 없이 보냄
......
This diff could not be displayed because it is too large.