Skip to content

Commit

Permalink
Update account fix2
Browse files Browse the repository at this point in the history
  • Loading branch information
hhassan01 committed Aug 30, 2024
1 parent 03b57e0 commit 4206ef0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/services/accountsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CreateAccountDto, UpdateAccountDto } from '../dto/account'
import { NotFoundException } from '../utils/exceptions'
import { SupportedCurrency } from '../constants/currencies'
import { AwsEventBridgeService } from './awsEventBridgeService'
import { filterUndefined } from 'src/utils/filterUndefined'

export class AccountsService {
private accountModel: Model<IAccount>
Expand Down Expand Up @@ -57,6 +58,8 @@ export class AccountsService {
if (updateAccountDto.currencies) {
this.updateBalancesForNewCurrencies(account, updateAccountDto.currencies)
}

Object.assign(account, filterUndefined(updateAccountDto))
const updatedAccount = await account.save()

const { id, customerId, currencies, balances } = updatedAccount
Expand Down
1 change: 0 additions & 1 deletion src/services/transactionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class TransactionsService {
)

if (createTransactionDto.type === TransactionType.INBOUND) {
console.log('running inbound')
account.balances.set(
createTransactionDto.currency,
(account.balances.get(createTransactionDto.currency) || 0) +
Expand Down
11 changes: 11 additions & 0 deletions src/utils/filterUndefined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function filterUndefined(obj: Record<string, any>): Record<string, any> {
const result: Record<string, any> = {}

for (const key in obj) {
if (obj[key] !== undefined) {
result[key] = obj[key]
}
}

return result
}
2 changes: 1 addition & 1 deletion tests/handlers/createTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('createTransactionHandler', () => {
balances: new Map([['USD', 100]]),
})
await account.save()
console.log({ account })

const event = {
body: JSON.stringify({
accountId: account._id.toString(),
Expand Down

0 comments on commit 4206ef0

Please sign in to comment.