diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 225e35d3..b541926f 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -27,11 +27,7 @@ export default async () => { if (Object.prototype.hasOwnProperty.call(groups, key)) { const group = groups[key]; const depIds = group.map((x) => x.id); - for (const dep of depIds) { - if (dep) { - await dependenceService.reInstall([dep]); - } - } + await dependenceService.reInstall(depIds as number[]); } } }); diff --git a/back/services/dependence.ts b/back/services/dependence.ts index 30609ed3..2cd1b51c 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -27,7 +27,7 @@ export default class DependenceService { return tab; }); const docs = await this.insert(tabs); - this.installOrUninstallDependencies(docs); + await this.installDependenceOneByOne(docs); return docs; } @@ -47,7 +47,7 @@ export default class DependenceService { status: DependenceStatus.installing, }); const newDoc = await this.updateDb(tab); - this.installOrUninstallDependencies([newDoc]); + await this.installDependenceOneByOne([newDoc]); return newDoc; } @@ -62,7 +62,7 @@ export default class DependenceService { { where: { id: ids } }, ); const docs = await DependenceModel.findAll({ where: { id: ids } }); - this.installOrUninstallDependencies(docs, false, force); + await this.installDependenceOneByOne(docs, false, force); return docs; } @@ -98,6 +98,18 @@ export default class DependenceService { } } + private async installDependenceOneByOne( + docs: Dependence[], + isInstall: boolean = true, + force: boolean = false, + ) { + for (const dep of docs) { + if (dep) { + await this.installOrUninstallDependencies([dep], isInstall, force); + } + } + } + public async reInstall(ids: number[]): Promise { await DependenceModel.update( { status: DependenceStatus.installing, log: [] }, @@ -105,7 +117,7 @@ export default class DependenceService { ); const docs = await DependenceModel.findAll({ where: { id: ids } }); - this.installOrUninstallDependencies(docs); + await this.installDependenceOneByOne(docs); return docs; }