Extract finding existing database item into separate method
This commit is contained in:
@@ -217,40 +217,18 @@ export class SkeletonQueryWizard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async selectExistingDatabase() {
|
private async selectExistingDatabase() {
|
||||||
if (this.language === undefined) {
|
|
||||||
throw new Error("Language is undefined");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.qlPackStoragePath === undefined) {
|
if (this.qlPackStoragePath === undefined) {
|
||||||
throw new Error("QL Pack storage path is undefined");
|
throw new Error("QL Pack storage path is undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
const databaseNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
|
const existingDatabaseItem = await this.findExistingDatabaseItem();
|
||||||
|
|
||||||
const existingDatabaseItem = await this.findDatabaseItemByNwo(
|
|
||||||
this.language,
|
|
||||||
databaseNwo,
|
|
||||||
this.databaseManager.databaseItems,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingDatabaseItem) {
|
if (existingDatabaseItem) {
|
||||||
// select the found database
|
// select the found database
|
||||||
await this.databaseManager.setCurrentDatabaseItem(existingDatabaseItem);
|
await this.databaseManager.setCurrentDatabaseItem(existingDatabaseItem);
|
||||||
} else {
|
} else {
|
||||||
const sameLanguageDatabaseItem = await this.findDatabaseItemByLanguage(
|
// download new database and select it
|
||||||
this.language,
|
await this.downloadDatabase();
|
||||||
this.databaseManager.databaseItems,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (sameLanguageDatabaseItem) {
|
|
||||||
// select the found database
|
|
||||||
await this.databaseManager.setCurrentDatabaseItem(
|
|
||||||
sameLanguageDatabaseItem,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// download new database and select it
|
|
||||||
await this.downloadDatabase();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,4 +264,24 @@ export class SkeletonQueryWizard {
|
|||||||
}
|
}
|
||||||
return dbs[0];
|
return dbs[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async findExistingDatabaseItem() {
|
||||||
|
if (this.language === undefined) {
|
||||||
|
throw new Error("Language is undefined");
|
||||||
|
}
|
||||||
|
|
||||||
|
const databaseNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
|
||||||
|
|
||||||
|
return (
|
||||||
|
(await this.findDatabaseItemByNwo(
|
||||||
|
this.language,
|
||||||
|
databaseNwo,
|
||||||
|
this.databaseManager.databaseItems,
|
||||||
|
)) ||
|
||||||
|
(await this.findDatabaseItemByLanguage(
|
||||||
|
this.language,
|
||||||
|
this.databaseManager.databaseItems,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user