* 获取项目列表 * @interface /project/list * @method GET * @category project * @foldnumber 10 * @param {Number} group_id 项目group_id,不能为空 * @returns {Object} * @example ./api/project/list.json
(ctx)
| 554 | */ |
| 555 | |
| 556 | async list(ctx) { |
| 557 | let group_id = ctx.params.group_id, |
| 558 | project_list = []; |
| 559 | |
| 560 | let groupData = await this.groupModel.get(group_id); |
| 561 | let isPrivateGroup = false; |
| 562 | if (groupData.type === 'private' && this.getUid() === groupData.uid) { |
| 563 | isPrivateGroup = true; |
| 564 | } |
| 565 | let auth = await this.checkAuth(group_id, 'group', 'view'); |
| 566 | let result = await this.Model.list(group_id); |
| 567 | let follow = await this.followModel.list(this.getUid()); |
| 568 | if (isPrivateGroup === false) { |
| 569 | for (let index = 0, item, r = 1; index < result.length; index++) { |
| 570 | item = result[index].toObject(); |
| 571 | if (item.project_type === 'private' && auth === false) { |
| 572 | r = await this.Model.checkMemberRepeat(item._id, this.getUid()); |
| 573 | if (r === 0) { |
| 574 | continue; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | let f = _.find(follow, fol => { |
| 579 | return fol.projectid === item._id; |
| 580 | }); |
| 581 | // 排序:收藏的项目放前面 |
| 582 | if (f) { |
| 583 | item.follow = true; |
| 584 | project_list.unshift(item); |
| 585 | } else { |
| 586 | item.follow = false; |
| 587 | project_list.push(item); |
| 588 | } |
| 589 | } |
| 590 | } else { |
| 591 | follow = follow.map(item => { |
| 592 | item = item.toObject(); |
| 593 | item._id = item.projectid |
| 594 | item.follow = true; |
| 595 | return item; |
| 596 | }); |
| 597 | project_list = _.uniq(follow.concat(result), item => item._id); |
| 598 | } |
| 599 | |
| 600 | ctx.body = yapi.commons.resReturn({ |
| 601 | list: project_list |
| 602 | }); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * 删除项目 |
no test coverage detected