From 643b240beb55c80b26e4acd73d19a45a52df8563 Mon Sep 17 00:00:00 2001 From: yksolanki9 Date: Sun, 5 Feb 2023 18:58:50 +0530 Subject: [PATCH] Pass account name and id for dryRun --- apps/api/src/app/import/import.service.ts | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index 7d6794c6f..b42fe8545 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -193,14 +193,16 @@ export class ImportService { userId }); - const accountIds = (await this.accountService.getAccounts(userId)).map( + const accounts = (await this.accountService.getAccounts(userId)).map( (account) => { - return account.id; + return { id: account.id, name: account.name }; } ); if (isDryRun) { - accountsDto.forEach((accountsDto) => accountIds.push(accountsDto.id)); + accountsDto.forEach((accountsDto) => + accounts.push({ id: accountsDto.id, name: accountsDto.name }) + ); } const activities: Activity[] = []; @@ -218,11 +220,15 @@ export class ImportService { unitPrice } of activitiesDto) { const date = parseISO((dateString)); - const validatedAccountId = accountIds.includes(accountId) - ? accountId - : undefined; + const validatedAccount = accounts.find( + (account) => account.id === accountId + ); - let order: OrderWithAccount; + let order: + | OrderWithAccount + | (Omit & { + Account?: { id: string; name: string }; + }); if (isDryRun) { order = { @@ -233,7 +239,7 @@ export class ImportService { type, unitPrice, userId, - accountId: validatedAccountId, + accountId: validatedAccount.id, accountUserId: undefined, createdAt: new Date(), id: uuidv4(), @@ -256,6 +262,7 @@ export class ImportService { url: null, ...assetProfiles[symbol] }, + Account: validatedAccount, symbolProfileId: undefined, updatedAt: new Date() }; @@ -268,7 +275,7 @@ export class ImportService { type, unitPrice, userId, - accountId: validatedAccountId, + accountId: validatedAccount.id, SymbolProfile: { connectOrCreate: { create: { @@ -290,6 +297,7 @@ export class ImportService { const value = new Big(quantity).mul(unitPrice).toNumber(); + //@ts-ignore activities.push({ ...order, value,