MCPcopy
hub / github.com/YMFE/yapi / findById

Method findById

server/controllers/user.js:408–440  ·  view source on GitHub ↗

* 获取用户个人信息 * @interface /user/find * @method GET * @param id 用户uid * @category user * @foldnumber 10 * @returns {Object} * @example

(ctx)

Source from the content-addressed store, hash-verified

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用户才有此权限

Callers 9

delMemberMethod · 0.45
changeMemberRoleMethod · 0.45
getUserdataMethod · 0.45
getMethod · 0.45
solveConflictMethod · 0.45
changePasswordMethod · 0.45
updateMethod · 0.45
initMethod · 0.45
checkLoginMethod · 0.45

Calls 2

getRoleMethod · 0.80
getUidMethod · 0.45

Tested by

no test coverage detected