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

Method addCol

server/controllers/interfaceCol.js:78–122  ·  view source on GitHub ↗

* 增加接口集 * @interface /col/add_col * @method POST * @category col * @foldnumber 10 * @param {Number} project_id * @param {String} name * @param {String} desc * @returns {Object} * @example

(ctx)

Source from the content-addressed store, hash-verified

76 */
77
78 async addCol(ctx) {
79 try {
80 let params = ctx.request.body;
81 params = yapi.commons.handleParams(params, {
82 name: 'string',
83 project_id: 'number',
84 desc: 'string'
85 });
86
87 if (!params.project_id) {
88 return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'));
89 }
90 if (!params.name) {
91 return (ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空'));
92 }
93
94 let auth = await this.checkAuth(params.project_id, 'project', 'edit');
95 if (!auth) {
96 return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限'));
97 }
98
99 let result = await this.colModel.save({
100 name: params.name,
101 project_id: params.project_id,
102 desc: params.desc,
103 uid: this.getUid(),
104 add_time: yapi.commons.time(),
105 up_time: yapi.commons.time()
106 });
107 let username = this.getUsername();
108 yapi.commons.saveLog({
109 content: `<a href="/user/profile/${this.getUid()}">${username}</a> 添加了接口集 <a href="/project/${
110 params.project_id
111 }/interface/col/${result._id}">${params.name}</a>`,
112 type: 'project',
113 uid: this.getUid(),
114 username: username,
115 typeid: params.project_id
116 });
117 // this.projectModel.up(params.project_id,{up_time: new Date().getTime()}).then();
118 ctx.body = yapi.commons.resReturn(result);
119 } catch (e) {
120 ctx.body = yapi.commons.resReturn(null, 402, e.message);
121 }
122 }
123
124 /**
125 * 获取一个接口集下的所有的测试用例

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