refactor(ApifoxService): 优化初始化逻辑和项目ID处理
- 修改init方法接收projectId参数并简化错误处理 - 统一通过init方法设置projectId - 移除getApiDetailsById中冗余的projectId处理 - 为getApiListByFolderName添加projectId参数支持
This commit is contained in:
1 parent
4386beea66
commit
87878ceca1
1 file changed
+9
-10
@@ -47,11 +47,10 @@ export class ApifoxService {
|
|||||||
* 初始化服务,获取branchId
|
* 初始化服务,获取branchId
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async init() {
|
async init(projectId) {
|
||||||
try {
|
if (projectId) {
|
||||||
|
this.projectId = projectId;
|
||||||
this.branchId = await this.getBranchId();
|
this.branchId = await this.getBranchId();
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +277,7 @@ export class ApifoxService {
|
|||||||
|
|
||||||
async getApiDetailByPath(path, projectId) {
|
async getApiDetailByPath(path, projectId) {
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
this.projectId = projectId;
|
await this.init(projectId);
|
||||||
}
|
}
|
||||||
const apiDetails = await this.getApiDetails();
|
const apiDetails = await this.getApiDetails();
|
||||||
const apiDetail = apiDetails.find((item) => item.path === path);
|
const apiDetail = apiDetails.find((item) => item.path === path);
|
||||||
@@ -288,10 +287,7 @@ export class ApifoxService {
|
|||||||
return this.getApiDetailResp(apiDetail);
|
return this.getApiDetailResp(apiDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getApiDetailsById(apiId, projectId) {
|
async getApiDetailsById(apiId) {
|
||||||
if (projectId) {
|
|
||||||
this.projectId = projectId;
|
|
||||||
}
|
|
||||||
const apiDetails = await this.getApiDetails();
|
const apiDetails = await this.getApiDetails();
|
||||||
const apiDetail = apiDetails.find((item) => item.id === apiId);
|
const apiDetail = apiDetails.find((item) => item.id === apiId);
|
||||||
if (!apiDetail) {
|
if (!apiDetail) {
|
||||||
@@ -302,7 +298,10 @@ export class ApifoxService {
|
|||||||
|
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
async getApiListByFolderName(folderName) {
|
async getApiListByFolderName(folderName, projectId) {
|
||||||
|
if (projectId) {
|
||||||
|
await this.init(projectId);
|
||||||
|
}
|
||||||
const folder = await this.getFolderByName(folderName);
|
const folder = await this.getFolderByName(folderName);
|
||||||
const apiDetails = await this.getApiDetails();
|
const apiDetails = await this.getApiDetails();
|
||||||
const apiList = apiDetails.filter((item) => item.folderId === folder.id);
|
const apiList = apiDetails.filter((item) => item.folderId === folder.id);
|
||||||
|
|||||||
Reference in new issue
Block a user