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

Method get

server/controllers/interface.js:400–434  ·  view source on GitHub ↗

* 获取项目分组 * @interface /interface/get * @method GET * @category interface * @foldnumber 10 * @param {Number} id 接口id,不能为空 * @returns {Object} * @example ./api/interface/get.json

(ctx)

Source from the content-addressed store, hash-verified

398 * @example ./api/interface/get.json
399 */
400 async get(ctx) {
401 let params = ctx.params;
402 if (!params.id) {
403 return (ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空'));
404 }
405
406 try {
407 let result = await this.Model.get(params.id);
408 if(this.$tokenAuth){
409 if(params.project_id !== result.project_id){
410 ctx.body = yapi.commons.resReturn(null, 400, 'token有误')
411 return;
412 }
413 }
414 // console.log('result', result);
415 if (!result) {
416 return (ctx.body = yapi.commons.resReturn(null, 490, '不存在的'));
417 }
418 let userinfo = await this.userModel.findById(result.uid);
419 let project = await this.projectModel.getBaseInfo(result.project_id);
420 if (project.project_type === 'private') {
421 if ((await this.checkAuth(project._id, 'project', 'view')) !== true) {
422 return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限'));
423 }
424 }
425 yapi.emitHook('interface_get', result).then();
426 result = result.toObject();
427 if (userinfo) {
428 result.username = userinfo.username;
429 }
430 ctx.body = yapi.commons.resReturn(result);
431 } catch (e) {
432 ctx.body = yapi.commons.resReturn(null, 402, e.message);
433 }
434 }
435
436 /**
437 * 接口列表

Callers 7

addMethod · 0.45
listByCatMethod · 0.45
upMethod · 0.45
delMethod · 0.45
solveConflictMethod · 0.45
upCatMethod · 0.45
delCatMethod · 0.45

Calls 3

getBaseInfoMethod · 0.80
findByIdMethod · 0.45
checkAuthMethod · 0.45

Tested by

no test coverage detected