* 获取自定义接口字段数据 * @interface /interface/get_custom_field * @method GET * @category interface * @foldnumber 10 * @param {String} app_code = '111' * @returns {Object} *
(ctx)
| 1053 | * |
| 1054 | */ |
| 1055 | async getCustomField(ctx) { |
| 1056 | let params = ctx.request.query; |
| 1057 | |
| 1058 | if (Object.keys(params).length !== 1) { |
| 1059 | return (ctx.body = yapi.commons.resReturn(null, 400, '参数数量错误')); |
| 1060 | } |
| 1061 | let customFieldName = Object.keys(params)[0]; |
| 1062 | let customFieldValue = params[customFieldName]; |
| 1063 | |
| 1064 | try { |
| 1065 | // 查找有customFieldName的分组(group) |
| 1066 | let groups = await this.groupModel.getcustomFieldName(customFieldName); |
| 1067 | if (groups.length === 0) { |
| 1068 | return (ctx.body = yapi.commons.resReturn(null, 404, '没有找到对应自定义接口')); |
| 1069 | } |
| 1070 | |
| 1071 | // 在每个分组(group)下查找对应project的id值 |
| 1072 | let interfaces = []; |
| 1073 | for (let i = 0; i < groups.length; i++) { |
| 1074 | let projects = await this.projectModel.list(groups[i]._id); |
| 1075 | |
| 1076 | // 在每个项目(project)中查找interface下的custom_field_value |
| 1077 | for (let j = 0; j < projects.length; j++) { |
| 1078 | let data = {}; |
| 1079 | let inter = await this.Model.getcustomFieldValue(projects[j]._id, customFieldValue); |
| 1080 | if (inter.length > 0) { |
| 1081 | data.project_name = projects[j].name; |
| 1082 | data.project_id = projects[j]._id; |
| 1083 | inter = inter.map((item, i) => { |
| 1084 | item = inter[i] = inter[i].toObject(); |
| 1085 | item.res_body = yapi.commons.json_parse(item.res_body); |
| 1086 | item.req_body_other = yapi.commons.json_parse(item.req_body_other); |
| 1087 | |
| 1088 | return item; |
| 1089 | }); |
| 1090 | |
| 1091 | data.list = inter; |
| 1092 | interfaces.push(data); |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | return (ctx.body = yapi.commons.resReturn(interfaces)); |
| 1097 | } catch (e) { |
| 1098 | yapi.commons.resReturn(null, 400, e.message); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | requiredSort(params) { |
| 1103 | return params.sort((item1, item2) => { |
nothing calls this directly
no test coverage detected