use find and remove unneccessary checks

This commit is contained in:
Nora
2022-12-22 10:53:54 +00:00
parent 28abd40963
commit 824f56d614
2 changed files with 8 additions and 12 deletions

View File

@@ -114,11 +114,14 @@ export class DbConfigStore extends DisposableObject {
const config: DbConfig = cloneDbConfig(this.config);
if (parentList) {
config.databases.remote.repositoryLists.forEach((list) => {
if (list.name === parentList) {
list.repositories.push(repoNwo);
const parent = config.databases.remote.repositoryLists.find(
(list) => list.name === parentList,
);
if (!parent) {
throw Error(`Cannot find parent list '${parentList}'`);
} else {
parent.repositories.push(repoNwo);
}
});
} else {
config.databases.remote.repositories.push(repoNwo);
}

View File

@@ -79,13 +79,6 @@ export class DbManager {
nwo: string,
parentList?: string,
): Promise<void> {
if (nwo === "") {
throw new Error("Repository name cannot be empty");
}
if (this.dbConfigStore.doesRemoteDbExist(nwo)) {
throw new Error(`The repository '${nwo}' already exists`);
}
await this.dbConfigStore.addRemoteRepo(nwo, parentList);
}