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

Method addCat

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

Source from the content-addressed store, hash-verified

885 }
886
887 async addCat(ctx) {
888 try {
889 let params = ctx.request.body;
890 params = yapi.commons.handleParams(params, {
891 name: 'string',
892 project_id: 'number',
893 desc: 'string'
894 });
895
896 if (!params.project_id) {
897 return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'));
898 }
899 if (!this.$tokenAuth) {
900 let auth = await this.checkAuth(params.project_id, 'project', 'edit');
901 if (!auth) {
902 return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限'));
903 }
904 }
905
906 if (!params.name) {
907 return (ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空'));
908 }
909
910 let result = await this.catModel.save({
911 name: params.name,
912 project_id: params.project_id,
913 desc: params.desc,
914 uid: this.getUid(),
915 add_time: yapi.commons.time(),
916 up_time: yapi.commons.time()
917 });
918
919 let username = this.getUsername();
920 yapi.commons.saveLog({
921 content: `<a href="/user/profile/${this.getUid()}">${username}</a> 添加了分类 <a href="/project/${
922 params.project_id
923 }/interface/api/cat_${result._id}">${params.name}</a>`,
924 type: 'project',
925 uid: this.getUid(),
926 username: username,
927 typeid: params.project_id
928 });
929
930 ctx.body = yapi.commons.resReturn(result);
931 } catch (e) {
932 ctx.body = yapi.commons.resReturn(null, 402, e.message);
933 }
934 }
935
936 async upCat(ctx) {
937 try {

Callers

nothing calls this directly

Calls 5

handleParamsMethod · 0.80
getUsernameMethod · 0.80
checkAuthMethod · 0.45
saveMethod · 0.45
getUidMethod · 0.45

Tested by

no test coverage detected