* 获取项目信息 * @interface /project/get * @method GET * @category project * @foldnumber 10 * @param {Number} id 项目id,不能为空 * @returns {Object} * @example ./api/project/get.json
(ctx)
| 517 | */ |
| 518 | |
| 519 | async get(ctx) { |
| 520 | let params = ctx.params; |
| 521 | let projectId= params.id || params.project_id; // 通过 token 访问 |
| 522 | let result = await this.Model.getBaseInfo(projectId); |
| 523 | |
| 524 | if (!result) { |
| 525 | return (ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目')); |
| 526 | } |
| 527 | if (result.project_type === 'private') { |
| 528 | if ((await this.checkAuth(result._id, 'project', 'view')) !== true) { |
| 529 | return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限')); |
| 530 | } |
| 531 | } |
| 532 | result = result.toObject(); |
| 533 | let catInst = yapi.getInst(interfaceCatModel); |
| 534 | let cat = await catInst.list(params.id); |
| 535 | result.cat = cat; |
| 536 | if (result.env.length === 0) { |
| 537 | result.env.push({ name: 'local', domain: 'http://127.0.0.1' }); |
| 538 | } |
| 539 | result.role = await this.getProjectRole(params.id, 'project'); |
| 540 | |
| 541 | yapi.emitHook('project_get', result).then(); |
| 542 | ctx.body = yapi.commons.resReturn(result); |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * 获取项目列表 |
no test coverage detected