From dcc857a2ba6f8827552eaa2741d3a2b375bb8abe Mon Sep 17 00:00:00 2001 From: yksolanki9 Date: Sun, 5 Feb 2023 13:40:42 +0530 Subject: [PATCH] Remove getAccountById method and its usage --- apps/api/src/app/account/account.service.ts | 7 ------- apps/api/src/app/import/import.service.ts | 12 ++++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/api/src/app/account/account.service.ts b/apps/api/src/app/account/account.service.ts index 32bf9f875..7c10fc31f 100644 --- a/apps/api/src/app/account/account.service.ts +++ b/apps/api/src/app/account/account.service.ts @@ -80,13 +80,6 @@ export class AccountService { }); } - public async getAccountById(accountId: string) { - const accounts = await this.accounts({ - where: { id: accountId } - }); - return accounts.length ? accounts[0] : null; - } - public async getAccounts(aUserId: string) { const accounts = await this.accounts({ include: { Order: true, Platform: true }, diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index 9210d9da8..5c3aa9e59 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -117,12 +117,20 @@ export class ImportService { }): Promise { const accountIdMapping: { [oldAccountId: string]: string } = {}; + const existingAccounts = await this.accountService.accounts({ + where: { + id: { + in: accountsDto.map((account) => account.id) + } + } + }); + //Create new accounts during dryRun so that new account IDs don't get invalidated if (isDryRun && accountsDto?.length) { for (let account of accountsDto) { //Check if there is any existing account with the same ID - const accountWithSameId = await this.accountService.getAccountById( - account.id + const accountWithSameId = existingAccounts.find( + (existingAccount) => existingAccount.id === account.id ); //If there is no account or if the account belongs to a different user then create a new account