Showing
4 changed files
with
40 additions
and
3 deletions
No preview for this file type
| ... | @@ -337,7 +337,7 @@ exports.setMedicine = async(ctx) => { | ... | @@ -337,7 +337,7 @@ exports.setMedicine = async(ctx) => { |
| 337 | // }; | 337 | // }; |
| 338 | 338 | ||
| 339 | //로그인한 유저의 약병 리스트 가져오기 | 339 | //로그인한 유저의 약병 리스트 가져오기 |
| 340 | -exports.getBottleList = async(ctx) => { | 340 | +exports.getHubsBottleList = async(ctx) => { |
| 341 | const token = ctx.req.headers.authorization; | 341 | const token = ctx.req.headers.authorization; |
| 342 | if(!token || !token.length) { | 342 | if(!token || !token.length) { |
| 343 | ctx.status = 401; | 343 | ctx.status = 401; |
| ... | @@ -374,3 +374,31 @@ exports.getBottleList = async(ctx) => { | ... | @@ -374,3 +374,31 @@ exports.getBottleList = async(ctx) => { |
| 374 | ctx.body = bottleList; | 374 | ctx.body = bottleList; |
| 375 | 375 | ||
| 376 | }; | 376 | }; |
| 377 | + | ||
| 378 | +//현재 로그인한 유저의 모든 약병을 가져옴 | ||
| 379 | +exports.getAllBottleList = async ctx => { | ||
| 380 | + const token = ctx.req.headers.authorization; | ||
| 381 | + if(!token || !token.length) { | ||
| 382 | + ctx.status = 401; | ||
| 383 | + return; | ||
| 384 | + } | ||
| 385 | + | ||
| 386 | + const { userId } = jwt.verify(token, process.env.JWT_SECRET); | ||
| 387 | + const user = await User.findByUserId(userId); | ||
| 388 | + if(!user || !user.userTypeCd || user.useYn !== 'Y') { | ||
| 389 | + ctx.status = 403; | ||
| 390 | + return; | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + const hubList = await Hub.find({ userId }); | ||
| 394 | + | ||
| 395 | + const bottleList = []; | ||
| 396 | + await Promise.all(hubList.map(async hub => { | ||
| 397 | + const _bottleList = await Bottle.find({ hubId : hub.hubId }); | ||
| 398 | + bottleList.push(..._bottleList); | ||
| 399 | + })); | ||
| 400 | + | ||
| 401 | + ctx.status = 200; | ||
| 402 | + ctx.body = bottleList; | ||
| 403 | + | ||
| 404 | +}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -57,6 +57,15 @@ bottle.patch('/:bottleId', bottleCtrl.setMedicine); | ... | @@ -57,6 +57,15 @@ bottle.patch('/:bottleId', bottleCtrl.setMedicine); |
| 57 | * url : http://localhost:4000/api/bottle/hub/:hubId | 57 | * url : http://localhost:4000/api/bottle/hub/:hubId |
| 58 | * return : bottle List(json type List) | 58 | * return : bottle List(json type List) |
| 59 | */ | 59 | */ |
| 60 | -bottle.get('/hub/:hubId', bottleCtrl.getBottleList) | 60 | +bottle.get('/hub/:hubId', bottleCtrl.getHubsBottleList); |
| 61 | + | ||
| 62 | +/** | ||
| 63 | + * 현재 로그인한 유저의 모든 약병을 조회함 | ||
| 64 | + * request parameter : x | ||
| 65 | + * url : http://localhost:4000/api/bottle/ | ||
| 66 | + * return : bottle List | ||
| 67 | + */ | ||
| 68 | +bottle.get('/', bottleCtrl.getAllBottleList); | ||
| 69 | + | ||
| 61 | 70 | ||
| 62 | module.exports = bottle; | 71 | module.exports = bottle; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -27,7 +27,7 @@ const BottleMedicineSchema = new Schema({ | ... | @@ -27,7 +27,7 @@ const BottleMedicineSchema = new Schema({ |
| 27 | type : Date, | 27 | type : Date, |
| 28 | required : true, | 28 | required : true, |
| 29 | default : Date.now, | 29 | default : Date.now, |
| 30 | - } | 30 | + }, |
| 31 | }); | 31 | }); |
| 32 | 32 | ||
| 33 | BottleMedicineSchema.methods.setDoctorId = function(doctorId) { | 33 | BottleMedicineSchema.methods.setDoctorId = function(doctorId) { | ... | ... |
-
Please register or login to post a comment