* 删除接口 * @interface /interface/del * @method GET * @category interface * @foldnumber 10 * @param {Number} id 接口id,不能为空 * @returns {Object} * @example ./api/interface/del.json
(ctx)
| 810 | */ |
| 811 | |
| 812 | async del(ctx) { |
| 813 | try { |
| 814 | let id = ctx.request.body.id; |
| 815 | |
| 816 | if (!id) { |
| 817 | return (ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空')); |
| 818 | } |
| 819 | |
| 820 | let data = await this.Model.get(id); |
| 821 | |
| 822 | if (data.uid != this.getUid()) { |
| 823 | let auth = await this.checkAuth(data.project_id, 'project', 'danger'); |
| 824 | if (!auth) { |
| 825 | return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限')); |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | // let inter = await this.Model.get(id); |
| 830 | let result = await this.Model.del(id); |
| 831 | yapi.emitHook('interface_del', id).then(); |
| 832 | await this.caseModel.delByInterfaceId(id); |
| 833 | let username = this.getUsername(); |
| 834 | this.catModel.get(data.catid).then(cate => { |
| 835 | yapi.commons.saveLog({ |
| 836 | content: `<a href="/user/profile/${this.getUid()}">${username}</a> 删除了分类 <a href="/project/${ |
| 837 | cate.project_id |
| 838 | }/interface/api/cat_${data.catid}">${cate.name}</a> 下的接口 "${data.title}"`, |
| 839 | type: 'project', |
| 840 | uid: this.getUid(), |
| 841 | username: username, |
| 842 | typeid: cate.project_id |
| 843 | }); |
| 844 | }); |
| 845 | this.projectModel.up(data.project_id, { up_time: new Date().getTime() }).then(); |
| 846 | ctx.body = yapi.commons.resReturn(result); |
| 847 | } catch (err) { |
| 848 | ctx.body = yapi.commons.resReturn(null, 402, err.message); |
| 849 | } |
| 850 | } |
| 851 | // 处理编辑冲突 |
| 852 | async solveConflict(ctx) { |
| 853 | try { |
no test coverage detected