MCPcopy
hub / github.com/YMFE/yapi / del

Method del

server/controllers/interface.js:812–850  ·  view source on GitHub ↗

* 删除接口 * @interface /interface/del * @method GET * @category interface * @foldnumber 10 * @param {Number} id 接口id,不能为空 * @returns {Object} * @example ./api/interface/del.json

(ctx)

Source from the content-addressed store, hash-verified

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 {

Callers 1

delCatMethod · 0.45

Calls 6

getUsernameMethod · 0.80
getMethod · 0.45
getUidMethod · 0.45
checkAuthMethod · 0.45
delByInterfaceIdMethod · 0.45
upMethod · 0.45

Tested by

no test coverage detected