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

Method listByMenu

server/controllers/interface.js:566–599  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

564 }
565
566 async listByMenu(ctx) {
567 let project_id = ctx.params.project_id;
568 if (!project_id) {
569 return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'));
570 }
571
572 let project = await this.projectModel.getBaseInfo(project_id);
573 if (!project) {
574 return (ctx.body = yapi.commons.resReturn(null, 406, '不存在的项目'));
575 }
576 if (project.project_type === 'private') {
577 if ((await this.checkAuth(project._id, 'project', 'view')) !== true) {
578 return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限'));
579 }
580 }
581
582 try {
583 let result = await this.catModel.list(project_id),
584 newResult = [];
585 for (let i = 0, item, list; i < result.length; i++) {
586 item = result[i].toObject();
587 list = await this.Model.listByCatid(item._id);
588 for (let j = 0; j < list.length; j++) {
589 list[j] = list[j].toObject();
590 }
591
592 item.list = list;
593 newResult[i] = item;
594 }
595 ctx.body = yapi.commons.resReturn(newResult);
596 } catch (err) {
597 ctx.body = yapi.commons.resReturn(null, 402, err.message);
598 }
599 }
600
601 /**
602 * 编辑接口

Callers

nothing calls this directly

Calls 4

getBaseInfoMethod · 0.80
listByCatidMethod · 0.80
checkAuthMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected