* 接口列表 * @interface /interface/list * @method GET * @category interface * @foldnumber 10 * @param {Number} project_id 项目id,不能为空 * @param {Number} page 当前页 * @param {Number} limit 每一页限制条数 * @returns {Object} * @example ./api/interface/list.json
(ctx)
| 446 | * @example ./api/interface/list.json |
| 447 | */ |
| 448 | async list(ctx) { |
| 449 | let project_id = ctx.params.project_id; |
| 450 | let page = ctx.request.query.page || 1, |
| 451 | limit = ctx.request.query.limit || 10; |
| 452 | let status = ctx.request.query.status, |
| 453 | tag = ctx.request.query.tag; |
| 454 | let project = await this.projectModel.getBaseInfo(project_id); |
| 455 | if (!project) { |
| 456 | return (ctx.body = yapi.commons.resReturn(null, 407, '不存在的项目')); |
| 457 | } |
| 458 | if (project.project_type === 'private') { |
| 459 | if ((await this.checkAuth(project._id, 'project', 'view')) !== true) { |
| 460 | return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限')); |
| 461 | } |
| 462 | } |
| 463 | if (!project_id) { |
| 464 | return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空')); |
| 465 | } |
| 466 | |
| 467 | try { |
| 468 | let result, count; |
| 469 | if (limit === 'all') { |
| 470 | result = await this.Model.list(project_id); |
| 471 | count = await this.Model.listCount({project_id}); |
| 472 | } else { |
| 473 | let option = {project_id}; |
| 474 | if (status) { |
| 475 | if (Array.isArray(status)) { |
| 476 | option.status = {"$in": status}; |
| 477 | } else { |
| 478 | option.status = status; |
| 479 | } |
| 480 | } |
| 481 | if (tag) { |
| 482 | if (Array.isArray(tag)) { |
| 483 | option.tag = {"$in": tag}; |
| 484 | } else { |
| 485 | option.tag = tag; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | result = await this.Model.listByOptionWithPage(option, page, limit); |
| 490 | count = await this.Model.listCount(option); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | ctx.body = yapi.commons.resReturn({ |
| 495 | count: count, |
| 496 | total: Math.ceil(count / limit), |
| 497 | list: result |
| 498 | }); |
| 499 | yapi.emitHook('interface_list', result).then(); |
| 500 | } catch (err) { |
| 501 | ctx.body = yapi.commons.resReturn(null, 402, err.message); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | async downloadCrx(ctx) { |
no test coverage detected