Skip to content

Commit

Permalink
♻️ refactor: update files based on review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcastr0 committed Dec 4, 2024
1 parent 94659fe commit fd181a2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 39 deletions.
7 changes: 5 additions & 2 deletions locales/extracted/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"common.noOptions": "No options found.",
"common.portfolio": "Portfolio",
"common.previousPage": "Previous page",
"common.records": "records",
"common.remove": "Remove",
"common.requiredFields": "(*) required fields.",
"common.resources": "Resources",
Expand Down Expand Up @@ -158,7 +159,7 @@
"ledgers.account.sheet.edit.title": "Edit {accountName}",
"ledgers.account.sheet.tabs.details": "Account Details",
"ledgers.accounts.createFirst": "Create first account",
"ledgers.accounts.subtitle": "{count} {count, plural, =0 {accounts found} one {acount found} other {accounts found}}",
"ledgers.accounts.subtitle": "{count} {count, plural, =0 {accounts found} one {account found} other {accounts found}}",
"ledgers.accounts.title": "Accounts",
"ledgers.assets.createButton": "Create your first Asset",
"ledgers.assets.emptyResource": "You haven't added any Asset within this Ledger yet.",
Expand Down Expand Up @@ -203,9 +204,10 @@
"ledgers.sheetCreate.description": "Fill in the data of the Ledger you wish to create.",
"ledgers.sheetCreate.title": "New Ledger",
"ledgers.subtitle": "Visualize and edit the Ledgers of your Organization.",
"ledgers.tab.accounts": "Accounts",
"ledgers.tab.assets": "Assets",
"ledgers.tab.overview": "Overview",
"ledgers.tab.portfolios-and-accounts": "Portfolios and Accounts",
"ledgers.tab.portfolios": "Portfolios",
"ledgers.tab.products": "Products",
"ledgers.title": "Ledgers",
"ledgers.toast.accountCreated": "{accountName} account successfully created",
Expand Down Expand Up @@ -250,6 +252,7 @@
"products.delete.description": "You are about to permanently delete this product. This action cannot be undone. Do you wish to continue?",
"settings.tab.organizations": "Organizations",
"settings.tab.otherSettings": "Other Settings",
"settings.tab.portfolios": "Portfolios",
"settings.tab.products": "Products",
"settings.tabs.organizations": "Organizations",
"settings.tabs.others": "Others Settings",
Expand Down
7 changes: 5 additions & 2 deletions locales/extracted/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
"ledgers.portfolio.sheet.edit.description": "Visualize e edite os campos do portfólio.",
"ledgers.portfolio.sheet.edit.title": "Editar {portfolioName}",
"ledgers.portfolio.sheet.title": "Novo Portfólio",
"ledgers.tab.portfolios-and-accounts": "Portfólios e Contas",
"portfolio.create": "Criar primeiro portfólio",
"entity.portfolio.description": "Insira o identificador único da entidade associado a este portfólio",
"entity.portfolio.entityId": "ID da Entidade",
Expand Down Expand Up @@ -280,5 +279,9 @@
"ledgers.portfolio.sheet.tabs.details": "Detalhes do Portfólio",
"ledgers.products.sheet.tabs.details": "Detalhes do Produto",
"notFound.backToHome": "Voltar para Home",
"ledgers.sheet.tabs.details": "Detalhes do Ledger"
"ledgers.sheet.tabs.details": "Detalhes do Ledger",
"common.records": "registros",
"ledgers.tab.accounts": "Contas",
"ledgers.tab.portfolios": "Portfólios",
"settings.tab.portfolios": "Portfólios"
}
10 changes: 3 additions & 7 deletions src/app/(routes)/ledgers/[id]/accounts/accounts-data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ const AccountRow: React.FC<AccountRowProps> = ({
: account.original.id
const metadataCount = Object.entries(account.original.metadata || []).length

const portfolioName = account.original.portfolio?.name ? (
account.original.portfolio.name
) : (
<Minus size={20} />
)

return (
<TableRow key={account.id}>
<TableCell>
Expand Down Expand Up @@ -123,7 +117,9 @@ const AccountRow: React.FC<AccountRowProps> = ({
)
)}
</TableCell>
<TableCell>{portfolioName}</TableCell>
<TableCell>
{account.original.portfolio?.name ?? <Minus size={20} />}
</TableCell>
<TableCell className="w-0">
<DropdownMenu>
<DropdownMenuTrigger asChild>
Expand Down
8 changes: 2 additions & 6 deletions src/app/(routes)/ledgers/[id]/accounts/accounts-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { MetadataField } from '@/components/form/metadata-field'
import { useListProducts } from '@/client/products'
import { useCreateAccount, useUpdateAccount } from '@/client/accounts'
import { useListPortfolios } from '@/client/portfolios'
import { isNil } from 'lodash'
import { isNil, omitBy } from 'lodash'
import { useListAssets } from '@/client/assets'
import useCustomToast from '@/hooks/use-custom-toast'
import { accountSchema } from '@/schema/account'
Expand Down Expand Up @@ -164,11 +164,7 @@ export const AccountSheet = ({
const { showSuccess, showError } = useCustomToast()

const handleSubmit = (data: FormData) => {
const cleanedData = JSON.parse(
JSON.stringify(data, (key, value) => {
return value === '' || value === null ? undefined : value
})
)
const cleanedData = omitBy(data, (value) => value === '' || isNil(value))

if (mode === 'create') {
createAccount({
Expand Down
2 changes: 2 additions & 0 deletions src/core/application/dto/portfolios-dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccountResponseDto } from './account-dto'
import { StatusDto } from './status.dto'

export interface CreatePortfolioDto {
Expand All @@ -20,6 +21,7 @@ export interface PortfolioResponseDto {
createdAt: Date
updatedAt: Date
deletedAt: Date | null
accounts?: AccountResponseDto[]
}

export interface UpdatePortfolioDto {
Expand Down
12 changes: 12 additions & 0 deletions src/core/application/mappers/portfolio-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { PortfolioEntity } from '@/core/domain/entities/portfolios-entity'
import { CreatePortfolioDto, PortfolioResponseDto } from '../dto/portfolios-dto'
import { PaginationEntity } from '@/core/domain/entities/pagination-entity'
import { PaginationMapper } from './pagination-mapper'
import { AccountMapper } from './account-mapper'
import { AccountResponseDto } from '../dto/account-dto'

export class PortfolioMapper {
public static toDomain(dto: CreatePortfolioDto): PortfolioEntity {
Expand Down Expand Up @@ -40,4 +42,14 @@ export class PortfolioMapper {
): PaginationEntity<PortfolioResponseDto> {
return PaginationMapper.toResponseDto(result, PortfolioMapper.toResponseDto)
}

public static toDtoWithAccounts(
portfolio: PortfolioEntity,
accounts: AccountResponseDto[]
): PortfolioResponseDto {
return {
...PortfolioMapper.toResponseDto(portfolio),
accounts: accounts.map(AccountMapper.toDto)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PaginationDto } from '../../dto/pagination-dto'
import { AccountMapper } from '../../mappers/account-mapper'
import { inject, injectable } from 'inversify'
import { groupBy } from 'lodash'
import { PortfolioMapper } from '../../mappers/portfolio-mapper'

export interface FetchPortfoliosWithAccounts {
execute: (
Expand Down Expand Up @@ -50,25 +51,12 @@ export class FetchPortfoliosWithAccountsUseCase
(account) => account.portfolioId || 'no_portfolio'
)

const portfoliosWithAccounts = portfoliosResult.items.map((portfolio) => {
const accounts = accountsGrouped[portfolio.id!] || []

return {
id: portfolio.id!,
ledgerId: portfolio.ledgerId!,
organizationId: portfolio.organizationId!,
name: portfolio.name!,
status: {
code: portfolio.status!.code!,
description: portfolio.status!.description!
},
metadata: portfolio.metadata!,
createdAt: portfolio.createdAt!,
updatedAt: portfolio.updatedAt!,
deletedAt: portfolio.deletedAt!,
accounts: accounts.map(AccountMapper.toDto)
}
})
const portfoliosWithAccounts = portfoliosResult.items.map((portfolio) =>
PortfolioMapper.toDtoWithAccounts(
portfolio,
(accountsGrouped[portfolio.id!] || []).map(AccountMapper.toDto)
)
)

const responseDTO: PaginationDto<any> = {
items: portfoliosWithAccounts,
Expand Down
6 changes: 3 additions & 3 deletions src/types/accounts-type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PortfolioType } from './portfolio-type'

export type AccountType = {
id: string
ledgerId: string
Expand All @@ -9,9 +11,7 @@ export type AccountType = {
entityId?: string
parentAccountId: string
portfolioId?: string | null
portfolio: {
name: string
}
portfolio: Pick<PortfolioType, 'name'>
portfolioName?: string
productId: string
status: {
Expand Down
4 changes: 4 additions & 0 deletions src/types/portfolio-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type PortfolioType = {
id: string
name: string
}

0 comments on commit fd181a2

Please sign in to comment.