(ctx)
| 362 | } |
| 363 | |
| 364 | async addCaseList(ctx) { |
| 365 | try { |
| 366 | let params = ctx.request.body; |
| 367 | params = yapi.commons.handleParams(params, { |
| 368 | project_id: 'number', |
| 369 | col_id: 'number' |
| 370 | }); |
| 371 | if (!params.interface_list || !Array.isArray(params.interface_list)) { |
| 372 | return (ctx.body = yapi.commons.resReturn(null, 400, 'interface_list 参数有误')); |
| 373 | } |
| 374 | |
| 375 | if (!params.project_id) { |
| 376 | return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空')); |
| 377 | } |
| 378 | |
| 379 | let auth = await this.checkAuth(params.project_id, 'project', 'edit'); |
| 380 | if (!auth) { |
| 381 | return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限')); |
| 382 | } |
| 383 | |
| 384 | if (!params.col_id) { |
| 385 | return (ctx.body = yapi.commons.resReturn(null, 400, '接口集id不能为空')); |
| 386 | } |
| 387 | |
| 388 | let data = { |
| 389 | uid: this.getUid(), |
| 390 | index: 0, |
| 391 | add_time: yapi.commons.time(), |
| 392 | up_time: yapi.commons.time(), |
| 393 | project_id: params.project_id, |
| 394 | col_id: params.col_id |
| 395 | }; |
| 396 | |
| 397 | for (let i = 0; i < params.interface_list.length; i++) { |
| 398 | let interfaceData = await this.interfaceModel.get(params.interface_list[i]); |
| 399 | data.interface_id = params.interface_list[i]; |
| 400 | data.casename = interfaceData.title; |
| 401 | |
| 402 | // 处理json schema 解析 |
| 403 | if ( |
| 404 | interfaceData.req_body_type === 'json' && |
| 405 | interfaceData.req_body_other && |
| 406 | interfaceData.req_body_is_json_schema |
| 407 | ) { |
| 408 | let req_body_other = yapi.commons.json_parse(interfaceData.req_body_other); |
| 409 | req_body_other = yapi.commons.schemaToJson(req_body_other, { |
| 410 | alwaysFakeOptionals: true |
| 411 | }); |
| 412 | |
| 413 | data.req_body_other = JSON.stringify(req_body_other); |
| 414 | } else { |
| 415 | data.req_body_other = interfaceData.req_body_other; |
| 416 | } |
| 417 | |
| 418 | data.req_body_type = interfaceData.req_body_type; |
| 419 | let caseResultData = await this.caseModel.save(data); |
| 420 | let username = this.getUsername(); |
| 421 | this.colModel.get(params.col_id).then(col => { |
nothing calls this directly
no test coverage detected