mirror of
https://github.com/YMFE/yapi.git
synced 2024-11-27 04:40:08 +08:00
feat: add nonexistent tags from /interface/(add/up/save)
(#1918)
This commit is contained in:
parent
31f2773e0c
commit
4d24c39748
@ -297,6 +297,8 @@ class interfaceController extends baseController {
|
||||
this.projectModel.up(params.project_id, { up_time: new Date().getTime() }).then();
|
||||
});
|
||||
|
||||
await this.autoAddTag(params);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}
|
||||
|
||||
@ -387,6 +389,45 @@ class interfaceController extends baseController {
|
||||
// return ctx.body = yapi.commons.resReturn(null, 400, 'path第一位必需为 /, 只允许由 字母数字-/_:.! 组成');
|
||||
}
|
||||
|
||||
async autoAddTag(params) {
|
||||
//检查是否提交了目前不存在的tag
|
||||
let tags = params.tag;
|
||||
if (tags && Array.isArray(tags) && tags.length > 0) {
|
||||
let projectData = await this.projectModel.get(params.project_id);
|
||||
let tagsInProject = projectData.tag;
|
||||
let needUpdate = false;
|
||||
if (tagsInProject && Array.isArray(tagsInProject) && tagsInProject.length > 0) {
|
||||
tags.forEach(tag => {
|
||||
if (!_.find(tagsInProject, item => {
|
||||
return item.name === tag;
|
||||
})) {//tag不存在
|
||||
needUpdate = true;
|
||||
tagsInProject.push({
|
||||
name: tag,
|
||||
desc: tag
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
needUpdate = true
|
||||
tagsInProject = []
|
||||
tags.forEach(tag => {
|
||||
tagsInProject.push({
|
||||
name: tag,
|
||||
desc: tag
|
||||
});
|
||||
});
|
||||
}
|
||||
if (needUpdate) {//需要更新tag
|
||||
let data = {
|
||||
tag: tagsInProject,
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
await this.projectModel.up(params.project_id, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目分组
|
||||
* @interface /interface/get
|
||||
@ -781,6 +822,8 @@ class interfaceController extends baseController {
|
||||
}
|
||||
|
||||
yapi.emitHook('interface_update', id).then();
|
||||
await this.autoAddTag(params);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user