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

Method copy

server/controllers/project.js:281–382  ·  view source on GitHub ↗

* 拷贝项目分组 * @interface /project/copy * @method POST * @category project * @foldnumber 10 * @param {String} name 项目名称,不能为空 * @param {String} basepath 项目基本路径,不能为空 * @param {Number} group_id 项目分组id,不能为空 * @param {Number} group_name 项目分组名称,不能为空 * @param {String} project_type pr

(ctx)

Source from the content-addressed store, hash-verified

279 * @example ./api/project/add.json
280 */
281 async copy(ctx) {
282 try {
283 let params = ctx.params;
284
285 // 拷贝项目的ID
286 let copyId = params._id;
287 if ((await this.checkAuth(params.group_id, 'group', 'edit')) !== true) {
288 return (ctx.body = yapi.commons.resReturn(null, 405, '没有权限'));
289 }
290
291 params.basepath = params.basepath || '';
292
293 let data = Object.assign(params, {
294 project_type: params.project_type || 'private',
295 uid: this.getUid(),
296 add_time: yapi.commons.time(),
297 up_time: yapi.commons.time(),
298 env: params.env || [{ name: 'local', domain: 'http://127.0.0.1' }]
299 });
300
301 delete data._id;
302 let result = await this.Model.save(data);
303 let colInst = yapi.getInst(interfaceColModel);
304 let catInst = yapi.getInst(interfaceCatModel);
305
306 // 增加集合
307 if (result._id) {
308 await colInst.save({
309 name: '公共测试集',
310 project_id: result._id,
311 desc: '公共测试集',
312 uid: this.getUid(),
313 add_time: yapi.commons.time(),
314 up_time: yapi.commons.time()
315 });
316
317 // 拷贝接口列表
318 let cat = params.cat;
319 for (let i = 0; i < cat.length; i++) {
320 let item = cat[i];
321 let catDate = {
322 name: item.name,
323 project_id: result._id,
324 desc: item.desc,
325 uid: this.getUid(),
326 add_time: yapi.commons.time(),
327 up_time: yapi.commons.time()
328 };
329 let catResult = await catInst.save(catDate);
330
331 // 获取每个集合中的interface
332 let interfaceData = await this.interfaceModel.listByInterStatus(item._id);
333
334 // 将interfaceData存到新的catID中
335 for (let key = 0; key < interfaceData.length; key++) {
336 let interfaceItem = interfaceData[key].toObject();
337 let data = Object.assign(interfaceItem, {
338 uid: this.getUid(),

Callers 13

ProjectCard.jsFile · 0.80
dFunction · 0.80
rFunction · 0.80
kFunction · 0.80
LFunction · 0.80
pFunction · 0.80
fFunction · 0.80
lFunction · 0.80
iFunction · 0.80
tFunction · 0.80
rFunction · 0.80

Calls 10

listByInterStatusMethod · 0.80
getRoleMethod · 0.80
getUserdataMethod · 0.80
getUsernameMethod · 0.80
checkAuthMethod · 0.45
getUidMethod · 0.45
saveMethod · 0.45
getMethod · 0.45
checkMemberRepeatMethod · 0.45
addMemberMethod · 0.45

Tested by

no test coverage detected