(ctx)
| 442 | } |
| 443 | |
| 444 | async cloneCaseList(ctx) { |
| 445 | try { |
| 446 | let params = ctx.request.body; |
| 447 | params = yapi.commons.handleParams(params, { |
| 448 | project_id: 'number', |
| 449 | col_id: 'number', |
| 450 | new_col_id: 'number' |
| 451 | }); |
| 452 | |
| 453 | const { project_id, col_id, new_col_id } = params; |
| 454 | |
| 455 | if (!project_id) { |
| 456 | return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空')); |
| 457 | } |
| 458 | |
| 459 | let auth = await this.checkAuth(params.project_id, 'project', 'edit'); |
| 460 | |
| 461 | if (!auth) { |
| 462 | return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限')); |
| 463 | } |
| 464 | |
| 465 | if (!col_id) { |
| 466 | return (ctx.body = yapi.commons.resReturn(null, 400, '被克隆的接口集id不能为空')); |
| 467 | } |
| 468 | |
| 469 | if (!new_col_id) { |
| 470 | return (ctx.body = yapi.commons.resReturn(null, 400, '克隆的接口集id不能为空')); |
| 471 | } |
| 472 | |
| 473 | let oldColCaselistData = await this.caseModel.list(col_id, 'all'); |
| 474 | |
| 475 | oldColCaselistData = oldColCaselistData.sort((a, b) => { |
| 476 | return a.index - b.index; |
| 477 | }); |
| 478 | |
| 479 | const newCaseList = []; |
| 480 | const oldCaseObj = {}; |
| 481 | let obj = {}; |
| 482 | |
| 483 | const handleTypeParams = (data, name) => { |
| 484 | let res = data[name]; |
| 485 | const type = Object.prototype.toString.call(res); |
| 486 | if (type === '[object Array]' && res.length) { |
| 487 | res = JSON.stringify(res); |
| 488 | try { |
| 489 | res = JSON.parse(handleReplaceStr(res)); |
| 490 | } catch (e) { |
| 491 | console.log('e ->', e); |
| 492 | } |
| 493 | } else if (type === '[object String]' && data[name]) { |
| 494 | res = handleReplaceStr(res); |
| 495 | } |
| 496 | return res; |
| 497 | }; |
| 498 | |
| 499 | const handleReplaceStr = str => { |
| 500 | if (str.indexOf('$') !== -1) { |
| 501 | str = str.replace(/\$\.([0-9]+)\./g, function(match, p1) { |
nothing calls this directly
no test coverage detected