Browse Source

Pass account name and id for dryRun

pull/1635/head
yksolanki9 3 years ago
parent
commit
643b240beb
  1. 26
      apps/api/src/app/import/import.service.ts

26
apps/api/src/app/import/import.service.ts

@ -193,14 +193,16 @@ export class ImportService {
userId userId
}); });
const accountIds = (await this.accountService.getAccounts(userId)).map( const accounts = (await this.accountService.getAccounts(userId)).map(
(account) => { (account) => {
return account.id; return { id: account.id, name: account.name };
} }
); );
if (isDryRun) { if (isDryRun) {
accountsDto.forEach((accountsDto) => accountIds.push(accountsDto.id)); accountsDto.forEach((accountsDto) =>
accounts.push({ id: accountsDto.id, name: accountsDto.name })
);
} }
const activities: Activity[] = []; const activities: Activity[] = [];
@ -218,11 +220,15 @@ export class ImportService {
unitPrice unitPrice
} of activitiesDto) { } of activitiesDto) {
const date = parseISO(<string>(<unknown>dateString)); const date = parseISO(<string>(<unknown>dateString));
const validatedAccountId = accountIds.includes(accountId) const validatedAccount = accounts.find(
? accountId (account) => account.id === accountId
: undefined; );
let order: OrderWithAccount; let order:
| OrderWithAccount
| (Omit<OrderWithAccount, 'Account'> & {
Account?: { id: string; name: string };
});
if (isDryRun) { if (isDryRun) {
order = { order = {
@ -233,7 +239,7 @@ export class ImportService {
type, type,
unitPrice, unitPrice,
userId, userId,
accountId: validatedAccountId, accountId: validatedAccount.id,
accountUserId: undefined, accountUserId: undefined,
createdAt: new Date(), createdAt: new Date(),
id: uuidv4(), id: uuidv4(),
@ -256,6 +262,7 @@ export class ImportService {
url: null, url: null,
...assetProfiles[symbol] ...assetProfiles[symbol]
}, },
Account: validatedAccount,
symbolProfileId: undefined, symbolProfileId: undefined,
updatedAt: new Date() updatedAt: new Date()
}; };
@ -268,7 +275,7 @@ export class ImportService {
type, type,
unitPrice, unitPrice,
userId, userId,
accountId: validatedAccountId, accountId: validatedAccount.id,
SymbolProfile: { SymbolProfile: {
connectOrCreate: { connectOrCreate: {
create: { create: {
@ -290,6 +297,7 @@ export class ImportService {
const value = new Big(quantity).mul(unitPrice).toNumber(); const value = new Big(quantity).mul(unitPrice).toNumber();
//@ts-ignore
activities.push({ activities.push({
...order, ...order,
value, value,

Loading…
Cancel
Save