* 获取用户个人信息 * @interface /user/find * @method GET * @param id 用户uid * @category user * @foldnumber 10 * @returns {Object} * @example
(ctx)
| 406 | * @example |
| 407 | */ |
| 408 | async findById(ctx) { |
| 409 | //根据id获取用户信息 |
| 410 | try { |
| 411 | let userInst = yapi.getInst(userModel); |
| 412 | let id = ctx.request.query.id; |
| 413 | |
| 414 | if (this.getRole() !== 'admin' && id != this.getUid()) { |
| 415 | return (ctx.body = yapi.commons.resReturn(null, 401, '没有权限')); |
| 416 | } |
| 417 | |
| 418 | if (!id) { |
| 419 | return (ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空')); |
| 420 | } |
| 421 | |
| 422 | let result = await userInst.findById(id); |
| 423 | |
| 424 | if (!result) { |
| 425 | return (ctx.body = yapi.commons.resReturn(null, 402, '不存在的用户')); |
| 426 | } |
| 427 | |
| 428 | return (ctx.body = yapi.commons.resReturn({ |
| 429 | uid: result._id, |
| 430 | username: result.username, |
| 431 | email: result.email, |
| 432 | role: result.role, |
| 433 | type: result.type, |
| 434 | add_time: result.add_time, |
| 435 | up_time: result.up_time |
| 436 | })); |
| 437 | } catch (e) { |
| 438 | return (ctx.body = yapi.commons.resReturn(null, 402, e.message)); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * 删除用户,只有admin用户才有此权限 |
no test coverage detected