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

Method getCaseEnvList

server/controllers/interfaceCol.js:165–195  ·  view source on GitHub ↗

* 获取一个接口集下的所有的测试用例的环境变量 * @interface /col/case_env_list * @method GET * @category col * @foldnumber 10 * @param {String} col_id 接口集id * @returns {Object} * @example

(ctx)

Source from the content-addressed store, hash-verified

163 * @example
164 */
165 async getCaseEnvList(ctx) {
166 try {
167 let id = ctx.query.col_id;
168 if (!id || id == 0) {
169 return (ctx.body = yapi.commons.resReturn(null, 407, 'col_id不能为空'));
170 }
171
172 let colData = await this.colModel.get(id);
173 let project = await this.projectModel.getBaseInfo(colData.project_id);
174 if (project.project_type === 'private') {
175 if ((await this.checkAuth(project._id, 'project', 'view')) !== true) {
176 return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限'));
177 }
178 }
179
180 // 通过col_id 找到 caseList
181 let projectList = await this.caseModel.list(id, 'project_id');
182 // 对projectList 进行去重处理
183 projectList = this.unique(projectList, 'project_id');
184
185 // 遍历projectList 找到项目和env
186 let projectEnvList = [];
187 for (let i = 0; i < projectList.length; i++) {
188 let result = await this.projectModel.getBaseInfo(projectList[i], 'name env');
189 projectEnvList.push(result);
190 }
191 ctx.body = yapi.commons.resReturn(projectEnvList);
192 } catch (e) {
193 ctx.body = yapi.commons.resReturn(null, 402, e.message);
194 }
195 }
196
197 requestParamsToObj(arr) {
198 if (!arr || !Array.isArray(arr) || arr.length === 0) {

Callers

nothing calls this directly

Calls 5

uniqueMethod · 0.95
getBaseInfoMethod · 0.80
getMethod · 0.45
checkAuthMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected