(ctx)
| 1184 | |
| 1185 | // 获取开放接口数据 |
| 1186 | async listByOpen(ctx) { |
| 1187 | let project_id = ctx.request.query.project_id; |
| 1188 | |
| 1189 | if (!project_id) { |
| 1190 | return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空')); |
| 1191 | } |
| 1192 | |
| 1193 | let project = await this.projectModel.getBaseInfo(project_id); |
| 1194 | if (!project) { |
| 1195 | return (ctx.body = yapi.commons.resReturn(null, 406, '不存在的项目')); |
| 1196 | } |
| 1197 | if (project.project_type === 'private') { |
| 1198 | if ((await this.checkAuth(project._id, 'project', 'view')) !== true) { |
| 1199 | return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限')); |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | let basepath = project.basepath; |
| 1204 | try { |
| 1205 | let result = await this.catModel.list(project_id), |
| 1206 | newResult = []; |
| 1207 | |
| 1208 | for (let i = 0, item, list; i < result.length; i++) { |
| 1209 | item = result[i].toObject(); |
| 1210 | list = await this.Model.listByInterStatus(item._id, 'open'); |
| 1211 | for (let j = 0; j < list.length; j++) { |
| 1212 | list[j] = list[j].toObject(); |
| 1213 | list[j].basepath = basepath; |
| 1214 | } |
| 1215 | |
| 1216 | newResult = [].concat(newResult, list); |
| 1217 | } |
| 1218 | |
| 1219 | ctx.body = yapi.commons.resReturn(newResult); |
| 1220 | } catch (err) { |
| 1221 | ctx.body = yapi.commons.resReturn(null, 402, err.message); |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | module.exports = interfaceController; |
nothing calls this directly
no test coverage detected