|
|
@ -7,6 +7,7 @@ import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interce |
|
|
import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; |
|
|
import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; |
|
|
import { AccountService } from '@ghostfolio/api/services/account/account.service'; |
|
|
import { AccountService } from '@ghostfolio/api/services/account/account.service'; |
|
|
import { ApiService } from '@ghostfolio/api/services/api/api.service'; |
|
|
import { ApiService } from '@ghostfolio/api/services/api/api.service'; |
|
|
|
|
|
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; |
|
|
import { |
|
|
import { |
|
|
CreateAccountBalanceDto, |
|
|
CreateAccountBalanceDto, |
|
|
CreateAccountDto, |
|
|
CreateAccountDto, |
|
|
@ -72,7 +73,7 @@ export class AccountsController { |
|
|
{ activities: true } |
|
|
{ activities: true } |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (!account || account?.activities.length > 0) { |
|
|
if (!account?.activities || account.activities.length > 0) { |
|
|
throw new HttpException( |
|
|
throw new HttpException( |
|
|
getReasonPhrase(StatusCodes.FORBIDDEN), |
|
|
getReasonPhrase(StatusCodes.FORBIDDEN), |
|
|
StatusCodes.FORBIDDEN |
|
|
StatusCodes.FORBIDDEN |
|
|
@ -173,7 +174,7 @@ export class AccountsController { |
|
|
return this.accountBalanceService.getAccountBalances({ |
|
|
return this.accountBalanceService.getAccountBalances({ |
|
|
userId, |
|
|
userId, |
|
|
filters: [{ id, type: 'ACCOUNT' }], |
|
|
filters: [{ id, type: 'ACCOUNT' }], |
|
|
userCurrency: userSettings.baseCurrency |
|
|
userCurrency: userSettings.baseCurrency ?? DEFAULT_CURRENCY |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -185,12 +186,9 @@ export class AccountsController { |
|
|
@Body() data: CreateAccountDto, |
|
|
@Body() data: CreateAccountDto, |
|
|
@Impersonation() { userId }: ImpersonationContext |
|
|
@Impersonation() { userId }: ImpersonationContext |
|
|
): Promise<AccountModel> { |
|
|
): Promise<AccountModel> { |
|
|
const { balance, tags: tagIds, ...accountData } = data; |
|
|
const { balance, platformId, tags: tagIds, ...accountData } = data; |
|
|
|
|
|
|
|
|
if (accountData.platformId) { |
|
|
|
|
|
const platformId = accountData.platformId; |
|
|
|
|
|
delete accountData.platformId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (platformId) { |
|
|
return this.accountService.createAccount({ |
|
|
return this.accountService.createAccount({ |
|
|
balance, |
|
|
balance, |
|
|
tagIds, |
|
|
tagIds, |
|
|
@ -202,8 +200,6 @@ export class AccountsController { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
delete accountData.platformId; |
|
|
|
|
|
|
|
|
|
|
|
return this.accountService.createAccount({ |
|
|
return this.accountService.createAccount({ |
|
|
balance, |
|
|
balance, |
|
|
tagIds, |
|
|
tagIds, |
|
|
@ -262,7 +258,7 @@ export class AccountsController { |
|
|
@RequiresScope(scopes.accountUpdate) |
|
|
@RequiresScope(scopes.accountUpdate) |
|
|
public async transferAccountBalance( |
|
|
public async transferAccountBalance( |
|
|
@Body() { accountIdFrom, accountIdTo, balance }: TransferBalanceDto, |
|
|
@Body() { accountIdFrom, accountIdTo, balance }: TransferBalanceDto, |
|
|
@Impersonation() { userId }: ImpersonationContext |
|
|
@Impersonation() { userId, userSettings }: ImpersonationContext |
|
|
) { |
|
|
) { |
|
|
const accountsOfUser = await this.accountService.getAccounts(userId); |
|
|
const accountsOfUser = await this.accountService.getAccounts(userId); |
|
|
|
|
|
|
|
|
@ -295,18 +291,21 @@ export class AccountsController { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const currency = |
|
|
|
|
|
accountFrom.currency ?? userSettings.baseCurrency ?? DEFAULT_CURRENCY; |
|
|
|
|
|
|
|
|
await this.accountService.updateAccountBalance({ |
|
|
await this.accountService.updateAccountBalance({ |
|
|
|
|
|
currency, |
|
|
userId, |
|
|
userId, |
|
|
accountId: accountFrom.id, |
|
|
accountId: accountFrom.id, |
|
|
amount: -balance, |
|
|
amount: -balance |
|
|
currency: accountFrom.currency |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
await this.accountService.updateAccountBalance({ |
|
|
await this.accountService.updateAccountBalance({ |
|
|
|
|
|
currency, |
|
|
userId, |
|
|
userId, |
|
|
accountId: accountTo.id, |
|
|
accountId: accountTo.id, |
|
|
amount: balance, |
|
|
amount: balance |
|
|
currency: accountFrom.currency |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -333,12 +332,9 @@ export class AccountsController { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { balance, tags: tagIds, ...accountData } = data; |
|
|
const { balance, platformId, tags: tagIds, ...accountData } = data; |
|
|
|
|
|
|
|
|
if (accountData.platformId) { |
|
|
|
|
|
const platformId = accountData.platformId; |
|
|
|
|
|
delete accountData.platformId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (platformId) { |
|
|
return this.accountService.updateAccount({ |
|
|
return this.accountService.updateAccount({ |
|
|
balance, |
|
|
balance, |
|
|
tagIds, |
|
|
tagIds, |
|
|
@ -356,9 +352,6 @@ export class AccountsController { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
// platformId is null, remove it
|
|
|
|
|
|
delete accountData.platformId; |
|
|
|
|
|
|
|
|
|
|
|
return this.accountService.updateAccount({ |
|
|
return this.accountService.updateAccount({ |
|
|
balance, |
|
|
balance, |
|
|
tagIds, |
|
|
tagIds, |
|
|
|