* 编辑项目 * @interface /project/up * @method POST * @category project * @foldnumber 10 * @param {Number} id 项目id,不能为空 * @param {String} name 项目名称,不能为空 * @param {String} basepath 项目基本路径,不能为空 * @param {String} [desc] 项目描述 * @returns {Object} * @example ./api/project/up.json
(ctx)
| 773 | * @example ./api/project/up.json |
| 774 | */ |
| 775 | async up(ctx) { |
| 776 | try { |
| 777 | let id = ctx.request.body.id; |
| 778 | let params = ctx.request.body; |
| 779 | |
| 780 | params = yapi.commons.handleParams(params, { |
| 781 | name: 'string', |
| 782 | basepath: 'string', |
| 783 | group_id: 'number', |
| 784 | desc: 'string', |
| 785 | pre_script: 'string', |
| 786 | after_script: 'string', |
| 787 | project_mock_script: 'string' |
| 788 | }); |
| 789 | |
| 790 | if (!id) { |
| 791 | return (ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空')); |
| 792 | } |
| 793 | |
| 794 | if ((await this.checkAuth(id, 'project', 'danger')) !== true) { |
| 795 | return (ctx.body = yapi.commons.resReturn(null, 405, '没有权限')); |
| 796 | } |
| 797 | |
| 798 | let projectData = await this.Model.get(id); |
| 799 | |
| 800 | if (params.basepath) { |
| 801 | if ((params.basepath = this.handleBasepath(params.basepath)) === false) { |
| 802 | return (ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | if (projectData.name === params.name) { |
| 807 | delete params.name; |
| 808 | } |
| 809 | |
| 810 | if (params.name) { |
| 811 | let checkRepeat = await this.Model.checkNameRepeat(params.name, params.group_id); |
| 812 | if (checkRepeat > 0) { |
| 813 | return (ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名')); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | let data = { |
| 818 | up_time: yapi.commons.time() |
| 819 | }; |
| 820 | |
| 821 | data = Object.assign({}, data, params); |
| 822 | |
| 823 | let result = await this.Model.up(id, data); |
| 824 | let username = this.getUsername(); |
| 825 | yapi.commons.saveLog({ |
| 826 | content: `<a href="/user/profile/${this.getUid()}">${username}</a> 更新了项目 <a href="/project/${id}/interface/api">${ |
| 827 | projectData.name |
| 828 | }</a>`, |
| 829 | type: 'project', |
| 830 | uid: this.getUid(), |
| 831 | username: username, |
| 832 | typeid: id |
no test coverage detected