Skip to content

Commit

Permalink
refactor: some bugs adjusts 🔨
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinezAvellan committed Jun 4, 2024
1 parent d4699e3 commit 26452dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (r *AccountPostgreSQLRepository) Update(ctx context.Context, organizationID
args = append(args, record.Alias)
}

if account.ProductID != "" {
if !common.IsNilOrEmpty(account.ProductID) {
updates = append(updates, "product_id = $"+strconv.Itoa(len(args)+1))
args = append(args, record.ProductID)
}
Expand Down
38 changes: 19 additions & 19 deletions components/ledger/internal/app/command/create-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,13 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
cai.EntityID = &portfolio.EntityID
}

account := &a.Account{
ID: uuid.New().String(),
InstrumentCode: cai.InstrumentCode,
Alias: cai.Alias,
Name: cai.Name,
Type: cai.Type,
ParentAccountID: cai.ParentAccountID,
ProductID: cai.ProductID,
OrganizationID: organizationID,
PortfolioID: portfolioID,
LedgerID: ledgerID,
EntityID: *cai.EntityID,
Balance: balance,
Status: status,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}

if !common.IsNilOrEmpty(cai.ParentAccountID) {
acc, err := uc.AccountRepo.Find(ctx, uuid.MustParse(organizationID), uuid.MustParse(ledgerID), uuid.MustParse(portfolioID), uuid.MustParse(*cai.ParentAccountID))
if err != nil {
return nil, err
}

if acc.InstrumentCode != account.InstrumentCode {
if acc.InstrumentCode != cai.InstrumentCode {
return nil, common.ValidationError{
EntityType: reflect.TypeOf(a.Account{}).Name(),
Title: "Mismatched Instrument Code",
Expand All @@ -95,6 +77,24 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
}
}

account := &a.Account{
ID: uuid.New().String(),
InstrumentCode: cai.InstrumentCode,
Alias: cai.Alias,
Name: cai.Name,
Type: cai.Type,
ParentAccountID: cai.ParentAccountID,
ProductID: cai.ProductID,
OrganizationID: organizationID,
PortfolioID: portfolioID,
LedgerID: ledgerID,
EntityID: *cai.EntityID,
Balance: balance,
Status: status,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}

port, err := uc.AccountRepo.Create(ctx, account)
if err != nil {
logger.Errorf("Error creating account: %v", err)
Expand Down

0 comments on commit 26452dd

Please sign in to comment.