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

Method delCat

server/controllers/interface.js:970–1012  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

968 }
969
970 async delCat(ctx) {
971 try {
972 let id = ctx.request.body.catid;
973 let catData = await this.catModel.get(id);
974 if (!catData) {
975 ctx.body = yapi.commons.resReturn(null, 400, '不存在的分类');
976 }
977
978 if (catData.uid !== this.getUid()) {
979 let auth = await this.checkAuth(catData.project_id, 'project', 'danger');
980 if (!auth) {
981 return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限'));
982 }
983 }
984
985 let username = this.getUsername();
986 yapi.commons.saveLog({
987 content: `<a href="/user/profile/${this.getUid()}">${username}</a> 删除了分类 "${
988 catData.name
989 }" 及该分类下的接口`,
990 type: 'project',
991 uid: this.getUid(),
992 username: username,
993 typeid: catData.project_id
994 });
995
996 let interfaceData = await this.Model.listByCatid(id);
997
998 interfaceData.forEach(async item => {
999 try {
1000 yapi.emitHook('interface_del', item._id).then();
1001 await this.caseModel.delByInterfaceId(item._id);
1002 } catch (e) {
1003 yapi.commons.log(e.message, 'error');
1004 }
1005 });
1006 await this.catModel.del(id);
1007 let r = await this.Model.delByCatid(id);
1008 return (ctx.body = yapi.commons.resReturn(r));
1009 } catch (e) {
1010 yapi.commons.resReturn(null, 400, e.message);
1011 }
1012 }
1013
1014 /**
1015 * 获取分类列表

Callers

nothing calls this directly

Calls 8

getUsernameMethod · 0.80
listByCatidMethod · 0.80
delByCatidMethod · 0.80
getMethod · 0.45
getUidMethod · 0.45
checkAuthMethod · 0.45
delByInterfaceIdMethod · 0.45
delMethod · 0.45

Tested by

no test coverage detected